GithubHelp home page GithubHelp logo

Exception in an import callback leaves the compiler in an inconsistent state, leading to `You shall not have another CompilerStack aside me` error on next compilation about solc-js HOT 13 OPEN

neocho avatar neocho commented on June 5, 2024
Exception in an import callback leaves the compiler in an inconsistent state, leading to `You shall not have another CompilerStack aside me` error on next compilation

from solc-js.

Comments (13)

cameel avatar cameel commented on June 5, 2024 1

Good point.

Ok then, I think we should close this but before we do, we should emphasize that point in the README more. I missed it myself when reading it. It should explicitly say that throwing an exception is not a valid thing to do. Might be a good idea to change the example we have there so that it has a try/catch block that would convert any error to { error: ... }.

Actually, I wonder if we couldn't wrap the callback in our own try/catch block and print a warning if any exception escapes. This seems to be a common mistake.

from solc-js.

cameel avatar cameel commented on June 5, 2024

May be the same thing as #575. Could you create a small, self-contained JS snippet that reproduces this?

from solc-js.

neocho avatar neocho commented on June 5, 2024

Yes, here's a script of it:
https://replit.com/@datboineo/solc-test#index.js

from solc-js.

cameel avatar cameel commented on June 5, 2024

Thanks! I managed to reproduce it. Minimal repro:

import solc from 'solc'

function importCallback(filePath) {
  throw new Error("IMPORT CALLBACK ERROR")
}

let input = {
  language: 'Solidity',
  sources: {'C.sol': {content: 'import "A.sol";'}},
}

try {
  solc.compile(JSON.stringify(input), {import: importCallback})
}
catch {
}

const output = solc.compile(JSON.stringify(input))
console.log(JSON.parse(output))

Looks like the problem happens when there is an error in the import callback, but you catch it and continue to use the compiler. I think that it must be leaving the compiler in an inconsistent state. The native binary has no import callback so it would just exit with an error. In JS you can catch the error and retry, which triggers this.

If that's the case then a workaround for this would probably be to unload the binary and load it again if you detect a crash in the callback.

A proper fix will require some debugging in the compiler to find out what's actually going on in there.

from solc-js.

neocho avatar neocho commented on June 5, 2024

cool thanks for the feedback! will try that out

from solc-js.

alexreyes avatar alexreyes commented on June 5, 2024

Also having this error

from solc-js.

ekpyron avatar ekpyron commented on June 5, 2024

As stated in the docs, the import callbacks have to return be it successfully or with an explicit error. Throwing exceptions in the callbacks is invalid - i.e. you need to make sure that you catch exceptions in the callback implementation. Given that, I'm inclined to close this issue.

from solc-js.

ekpyron avatar ekpyron commented on June 5, 2024

Not sure how common of a mistake it is - the problem in wrapping it ourselves is that it's technically overhead for anyone who uses a proper callback as intended - and we'd need to decide what to return after catching... So yeah, changing the README and making this more explicit sounds good - but maybe then we can first wait and see if this still pops up again before trying to wrap this ourselves?

from solc-js.

cameel avatar cameel commented on June 5, 2024

we'd need to decide what to return after catching...

We can simply rethrow, just printing a warning beforehand. This won't fix the problem but will give a better clue as to what the issue is. This report shows that the messages you get currently do not make it easy to figure out :)

but maybe then we can first wait and see if this still pops up again before trying to wrap this ourselves?

I think the overhead would not be that significant (come on, the whole callback is JS, that's already slow :)). I think that just adding a warning would not hurt to do right away, but documenting it properly is the most important here.

from solc-js.

alieltareb1 avatar alieltareb1 commented on June 5, 2024

Hi

from solc-js.

alieltareb1 avatar alieltareb1 commented on June 5, 2024

Low

from solc-js.

alieltareb1 avatar alieltareb1 commented on June 5, 2024

Down

from solc-js.

alieltareb1 avatar alieltareb1 commented on June 5, 2024

Up

from solc-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.