-
Notifications
You must be signed in to change notification settings - Fork 480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
#675
Comments
May be the same thing as #575. Could you create a small, self-contained JS snippet that reproduces this? |
Yes, here's a script of it: |
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. |
You shall not have another CompilerStack aside me
on next compilation
You shall not have another CompilerStack aside me
on next compilationYou shall not have another CompilerStack aside me
error on next compilation
cool thanks for the feedback! will try that out |
Also having this error |
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. |
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 Actually, I wonder if we couldn't wrap the callback in our own |
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? |
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 :)
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. |
Hi, I'm getting an internal exception error but I'm not too sure why. I'm running solc on an express server.
Steps to getting this error:
solc.compile()
throws errorError i'm getting:
The text was updated successfully, but these errors were encountered: