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

Print plugin errors with causes #30265

Open
badeball opened this issue Sep 22, 2024 · 0 comments
Open

Print plugin errors with causes #30265

badeball opened this issue Sep 22, 2024 · 0 comments
Labels
topic: plugins ⚙️ type: feature New feature that does not currently exist

Comments

@badeball
Copy link
Contributor

badeball commented Sep 22, 2024

What would you like?

It seems like Error.prototype.stack is used to print errors originating from a plugin event handler, ref.

https://github.com/cypress-io/cypress/blob/v13.14.2/packages/errors/src/errors.ts#L1380

.. and

https://github.com/cypress-io/cypress/blob/v13.14.2/packages/errors/src/errTemplate.ts#L321

This removes original errors that have been wrapped using cause, as seen below.

$ node
Welcome to Node.js v18.20.4.
Type ".help" for more information.
> (new Error("foo", { cause: new Error("bar") })).stack
'Error: foo\n' +
  '    at REPL1:1:2\n' +
  '    at ContextifyScript.runInThisContext (node:vm:121:12)\n' +
  '    at REPLServer.defaultEval (node:repl:599:22)\n' +
  '    at bound (node:domain:433:15)\n' +
  '    at REPLServer.runBound [as eval] (node:domain:444:12)\n' +
  '    at REPLServer.onLine (node:repl:929:10)\n' +
  '    at REPLServer.emit (node:events:529:35)\n' +
  '    at REPLServer.emit (node:domain:489:12)\n' +
  '    at [_onLine] [as _onLine] (node:internal/readline/interface:423:12)\n' +
  '    at [_line] [as _line] (node:internal/readline/interface:894:18)'

I propose that you use util.inspect or something similar, to preserve this information, like seen below.

$ node
Welcome to Node.js v18.20.4.
Type ".help" for more information.
> util.inspect(new Error("foo", { cause: new Error("bar") }))
'Error: foo\n' +
  '    at REPL1:1:14\n' +
  '    at ContextifyScript.runInThisContext (node:vm:121:12)\n' +
  '    ... 7 lines matching cause stack trace ...\n' +
  '    at [_line] [as _line] (node:internal/readline/interface:894:18) {\n' +
  '  [cause]: Error: bar\n' +
  '      at REPL1:1:40\n' +
  '      at ContextifyScript.runInThisContext (node:vm:121:12)\n' +
  '      at REPLServer.defaultEval (node:repl:599:22)\n' +
  '      at bound (node:domain:433:15)\n' +
  '      at REPLServer.runBound [as eval] (node:domain:444:12)\n' +
  '      at REPLServer.onLine (node:repl:929:10)\n' +
  '      at REPLServer.emit (node:events:529:35)\n' +
  '      at REPLServer.emit (node:domain:489:12)\n' +
  '      at [_onLine] [as _onLine] (node:internal/readline/interface:423:12)\n' +
  '      at [_line] [as _line] (node:internal/readline/interface:894:18)\n' +
  '}'

Why is this needed?

To preserve potentially important information.

Other

No response

badeball added a commit to badeball/cypress-cucumber-preprocessor that referenced this issue Sep 22, 2024
Additionally, for users that haven't enabled messages, one is generated
anyway in the users temporary location. This will hopefully shed some
light onto a previously reported and hard-to-reproduce issue [1].

I would ideally have liked to use error cause for this, but Cypress will
swallow this [2].

[1] #1161
[2] cypress-io/cypress#30265
badeball added a commit to badeball/cypress-cucumber-preprocessor that referenced this issue Sep 24, 2024
Additionally, for users that haven't enabled messages, one is generated
anyway in the users temporary location. This will hopefully shed some
light onto a previously reported and hard-to-reproduce issue [1].

I would ideally have liked to use error cause for this, but Cypress will
swallow this [2].

[1] #1161
[2] cypress-io/cypress#30265
@jennifer-shehane jennifer-shehane added type: feature New feature that does not currently exist topic: plugins ⚙️ labels Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: plugins ⚙️ type: feature New feature that does not currently exist
Projects
None yet
Development

No branches or pull requests

2 participants