-
Notifications
You must be signed in to change notification settings - Fork 62
solc package greedy on exception handling, causes extra error information in stack traces in Node #167
Comments
When I run |
Interesting. I made an assumption - that |
Would be nice to solve this, I was always annoyed by that. The reason for that code seems to be a bit more complex. The catch for All the relevant sources:
Also slightly relevant:
|
@tcoulter @redsquirrel did you had a chance to check in Emscripten if there's a proper solution to this? |
@axic No, I'm still using |
Same. I just added this to Truffle, removing the listener right after requiring var solc = require("solc");
// Clean up after solc.
var listeners = process.listeners("uncaughtException");
var solc_listener = listeners[listeners.length - 1];
process.removeListener("uncaughtException", solc_listener); I keep a reference to the listener and add it back before compiling, and remove it after compiling, just in case it's needed. |
Would be nice to find a proper solution and have it included in https://github.com/ethereum/solc-js. The above seems very node specific and wouldn't possible work well in the browser 😃 |
Agreed. |
This is tracked now in ethereum/solc-js#34. |
Refactoring:: add events
After compiling with browser solidity in Node, all uncaught exceptions (i.e., bad code or application errors) will result in an error message similar to the following:
Ignore the actual error message ("TypeError: ...") -- it doesn't matter in this case. However, notice the stack trace is prefixed with a long line of extra code. This extra code obfuscates the error message and makes it harder to read the stack trace to determine what went wrong. On this github ticket, you can scroll to the right in the code box above to see how long this output is. Now imagine this output in an environment where the output wraps, like in a terminal window when running automated tests.
Fortunately there's a way to remove this extra code information from stack traces:
This works because it prevents the solc package from catching the error and rethrowing, which is the cause of the extra stack trace information above. This method is good in that it makes error messages that occur after compiling much cleaner, but it in itself is greedy. What if there are
uncaughtException
handlers that still need to exist as a function of my application? In most cases this isn't an issue, but it's easy to imagine cases where this becomes a problem.To fix this, I think as part of the
compile
function the solc package should remove its own listener onprocess
'suncaughtException
event. Since the solc package has access to the handler that was added on theuncaughtException
event, it should be able to remove that handler without affecting any other event handlers, and it should do so before thecompile
function returns.Here's a quick script that exposes the issue:
Notice you get the following output:
To hit the point home once more, here's what it looks like in my terminal window:
Thanks!
The text was updated successfully, but these errors were encountered: