Open Macil opened 7 months ago
Yargs is catching and rethrowing the error. The cjs runtime is showing the rethrow line, which is in the big ugly blob of minified javascript. The esm runtime is showing the original throw line. I don't think yargs is at fault as such.
I wonder if getting line breaks into the cjs implementation would be worthwhile to at least avoid the code dump without significantly changing the overall size.
The behaviour is similar with yargs@16
except you see a single line of code for the rethrow in cjs since the implementation has line breaks. I tried the even node versions back to node 10 and using cjs they all showed the rethrow line first in the error output.
Here is the error with esm and node@17 and node v20.11.1 which shows the throw line and not the rethrow line:
% node esm.mjs upload --commit ABC
uploading (commit: ABC)
file:///Users/john/Documents/Sandpits/yargs/issues/2395/esm.mjs:17
throw new Error('uh oh upload failed');
^
Error: uh oh upload failed
at Object.handler (file:///Users/john/Documents/Sandpits/yargs/issues/2395/esm.mjs:17:13)
at file:///Users/john/Documents/Sandpits/yargs/issues/2395/node_modules/yargs/build/lib/command.js:206:54
at maybeAsyncResult (file:///Users/john/Documents/Sandpits/yargs/issues/2395/node_modules/yargs/build/lib/utils/maybe-async-result.js:9:15)
at CommandInstance.handleValidationAndGetResult (file:///Users/john/Documents/Sandpits/yargs/issues/2395/node_modules/yargs/build/lib/command.js:205:25)
at CommandInstance.applyMiddlewareAndGetResult (file:///Users/john/Documents/Sandpits/yargs/issues/2395/node_modules/yargs/build/lib/command.js:245:20)
at CommandInstance.runCommand (file:///Users/john/Documents/Sandpits/yargs/issues/2395/node_modules/yargs/build/lib/command.js:128:20)
at [runYargsParserAndExecuteCommands] (file:///Users/john/Documents/Sandpits/yargs/issues/2395/node_modules/yargs/build/lib/yargs-factory.js:1386:105)
at YargsInstance.parse (file:///Users/john/Documents/Sandpits/yargs/issues/2395/node_modules/yargs/build/lib/yargs-factory.js:707:63)
at file:///Users/john/Documents/Sandpits/yargs/issues/2395/esm.mjs:20:4
at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
Node.js v20.11.1
If a command handler throws an error, I get a massive error message full of minified javascript. In a terminal it covers tons of pages of space. It seems to be printing out yargs' minified js code and I can't understand why. (I think Node usually tries to point to where an error happened within an application's source code when an error is thrown during initialization of a module, but I don't understand why it's trying to point inside of yargs' js code when that's not where the error is. Is yargs doing something to cause this?)
Using yargs 17.7.2 and node v20.11.1, v21.7.1.