Background: I developed a small module system for node.js that asynchronously loads all required code from a separate source server and compiles it with eval(code). My problem is that for all run-time errors in such "eval-ed" code, the stack trace shows <anonymous> as the file name --- I cannot distinguish which code piece is referred to.
My question: Is there a way to set the file-name for eval so that the stack trace shows some program-defined string instead of <anonymous>?
My current (imperfect) solution: As of now, I write the code to a file and load it with require(file). This will sow the file name --- but it is a complicated workaround.
Note: Normally, the run-time errors do not show up at the compilation of the eval call, but later, when the compiled code is used. Thus, try/catch around the eval does not help to identify which code piece failed.
Eventually, this new feature of the V8 engine will make its way to Node.js:
Issue 2948: Support //# sourceURL= and //# sourceMappingURL= in v8's parser
This method works for Browsers currently.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With