Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The cause property of an error isn't included in the output #157

Open
merceyz opened this issue Feb 7, 2024 · 0 comments
Open

The cause property of an error isn't included in the output #157

merceyz opened this issue Feb 7, 2024 · 0 comments

Comments

@merceyz
Copy link
Contributor

merceyz commented Feb 7, 2024

When an error is thrown the cause property is not included in the output

import { runExit, Command } from 'clipanion';

runExit(
	class extends Command {
		async execute() {
			throw new Error(`foo`, { cause: new Error(`bar`) });
		}
	},
);

Output:

Internal Error: foo
    at Command.execute (file:///tmp/tmp.v2V9v1f760/test.mjs:6:10)
    at Command.validateAndExecute (/tmp/tmp.v2V9v1f760/node_modules/clipanion/lib/advanced/Command.js:73:37)
    at /tmp/tmp.v2V9v1f760/node_modules/clipanion/lib/advanced/Cli.js:229:53
    at noopCaptureActivator (/tmp/tmp.v2V9v1f760/node_modules/clipanion/lib/advanced/Cli.js:457:12)
    at Cli.run (/tmp/tmp.v2V9v1f760/node_modules/clipanion/lib/advanced/Cli.js:229:30)
    at Cli.runExit (/tmp/tmp.v2V9v1f760/node_modules/clipanion/lib/advanced/Cli.js:238:39)
    at runExit (/tmp/tmp.v2V9v1f760/node_modules/clipanion/lib/advanced/Cli.js:16:16)
    at file:///tmp/tmp.v2V9v1f760/test.mjs:3:1
    at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:336:24)

For comparison this is what Node.js prints:

file:///tmp/tmp.v2V9v1f760/test.mjs:1
throw new Error(`foo`, {cause: new Error(`bar`)});
      ^

Error: foo
    at file:///tmp/tmp.v2V9v1f760/test.mjs:1:7
    at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
    ... 2 lines matching cause stack trace ...
    at async handleMainPromise (node:internal/modules/run_main:106:12) {
  [cause]: Error: bar
      at file:///tmp/tmp.v2V9v1f760/test.mjs:1:32
      at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
      at async ModuleLoader.import (node:internal/modules/esm/loader:336:24)
      at async loadESM (node:internal/process/esm_loader:34:7)
      at async handleMainPromise (node:internal/modules/run_main:106:12)
}

Node.js v18.19.0

Ref nodejs/corepack#365 where I ran into this.

@merceyz merceyz changed the title The cause property of an error isn't included The cause property of an error isn't included in the output Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant