You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, thanks for the great package. I would like to request an improvement to how the package handles stack traces when the imported script throws an exception during execution. In my current usage (importFromString without --experimental-vm-modules enabled, i.e. the one that falls back on requireFromString internally), if my imported string throws an exception, the stack trace is unhelpful because:
the filename defaults to evalmachine.<anonymous>
the line numbers are wrong because module-from-string prepends its own code and also seems to reformat the input string
Is it possible to please improve the stack traces?
One idea/suggestion I have for this is to expose more options from vm.runInNewContext to make this possible, particularly the filename and lineOffset options. I mean roughly like this (then the usages have more control over displaying a meaningful stack trace, although I'm not quite sure how to handle the line offsets given the reformatting of the input - perhaps you could also provide an option to preserve original formatting):
bad
real-migration-filename.js:4
throw new Error("bad")
^
Error: bad
at migration (real-migration-filename.js:104:15)
at real-migration-filename.js:106:6
at Script.runInContext (vm.js:144:12)
at Script.runInNewContext (vm.js:149:17)
What do you think?
The text was updated successfully, but these errors were encountered:
I will expose an option filename to fix this, it should be just a few lines of code.
As for line offsets, I think it might be possible to reformat the error stack using the sourcemap emitted by esbuild's transform function, which importFromString without --experimental-vm-modules uses to transform ES Module to CommonJS.
Hello, thanks for the great package. I would like to request an improvement to how the package handles stack traces when the imported script throws an exception during execution. In my current usage (
importFromString
without--experimental-vm-modules
enabled, i.e. the one that falls back onrequireFromString
internally), if my imported string throws an exception, the stack trace is unhelpful because:evalmachine.<anonymous>
module-from-string
prepends its own code and also seems to reformat the input stringIs it possible to please improve the stack traces?
One idea/suggestion I have for this is to expose more options from vm.runInNewContext to make this possible, particularly the
filename
andlineOffset
options. I mean roughly like this (then the usages have more control over displaying a meaningful stack trace, although I'm not quite sure how to handle the line offsets given the reformatting of the input - perhaps you could also provide an option to preserve original formatting):What do you think?
The text was updated successfully, but these errors were encountered: