0

Node can print an uncaught exception trace when it exits due to an uncaught exception. This feature is enabled when I pass --trace-uncaught to node.

How do I enable this feature from the source code from within my script?

Perhaps something along the lines of node.trace_uncaught = true?

  • Seems like this question is already answered [here](https://stackoverflow.com/a/40867663/18891587) – Jaood_xD Jan 30 '23 at 10:01
  • @Jaood_xD It does not, Please read my question carefully. – Sir Nonchalant Jan 30 '23 at 10:06
  • You can't apply command line arguments to already running environment, so the only way to reach the same result is to attach listener to process errors as shown in the linked answer – Jaood_xD Jan 30 '23 at 11:01

1 Answers1

0

I haven't found a general solution to this yet. For now, I'll just (ab)use linux and sh to achieve what I want by adding this line to the top of my script:

//bin/true; exec /usr/bin/env node --trace-uncaught "$0" "$@"

This line uses sh to launch node with the desired flag. I'll leave this question open in case someone posts a proper cross-platform solution.