Comments (13)
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.
May be the same thing as #575. Could you create a small, self-contained JS snippet that reproduces this?
from solc-js.
Yes, here's a script of it:
https://replit.com/@datboineo/solc-test#index.js
from solc-js.
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.
cool thanks for the feedback! will try that out
from solc-js.
Also having this error
from solc-js.
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.
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.
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.
Hi
from solc-js.
Low
from solc-js.
Down
from solc-js.
Up
from solc-js.
Related Issues (20)
- Switch to audited and fast version of sha3/keccak HOT 4
- Does solc.loadRemoteVersion() download a new version of solc each time it is run? HOT 2
- Different bytecode when compiling from both solc-js and remix IDE
- cannot uninstall HOT 2
- OSError: [Errno 86] Bad CPU type in executable: HOT 1
- Cannot remap openzeppelin to use when I compile with solc HOT 1
- Release types on npm HOT 3
- Handle standard JSON transalation with `outputSelection` for `=<0.4.19`
- Failed to compile large json inputs HOT 1
- Callback not supported... HOT 2
- Identifier already declared HOT 2
- solc-select is out of date. Please run `solc-select upgrade` HOT 1
- Support for `--metadata` flag HOT 4
- 0.8.23 npm release won't install on Windows due to a stray dependency HOT 3
- findImports fallback on webWorkers not working HOT 5
- loadRemoteVersion is not working with jest test HOT 3
- 'Expected Pragma' error in solc but same code compiles in remix HOT 1
- Improvement: `content` not a key in solidity `input description` in solidity official doc (except under `destructible`) .
- Web3ContractError: code couldn't be stored HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from solc-js.