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

inspect: print individual AggregateError.errors #43645

Closed
LiviaMedeiros opened this issue Jul 1, 2022 · 3 comments · Fixed by #43646
Closed

inspect: print individual AggregateError.errors #43645

LiviaMedeiros opened this issue Jul 1, 2022 · 3 comments · Fixed by #43646
Labels
errors Issues and PRs related to JavaScript errors originated in Node.js core. feature request Issues that request new features to be added to Node.js. inspector Issues and PRs related to the V8 inspector protocol

Comments

@LiviaMedeiros
Copy link
Contributor

What is the problem this feature will solve?

> (() => {
throw new AggregateError([
  new TypeError('blep'),
  new RangeError('blop')
], 'gwak');
})();
Uncaught AggregateError: gwak
    at REPL6:2:7

When AggregateError is uncaught or inspected by util.inspect(), its errors property is ignored, so all individual errors are being swallowed. We can't get information about what exactly happened, where it happened, even how many errors there were.

What is the feature you are proposing to solve the problem?

Printing all .errors with their respective stacktraces, either adding it to AggregateError info or replacing it.

What alternatives have you considered?

Abbreviated output, something like AggregateError[ TypeError, TypeError, EvalError ]. This still doesn't provide enough info: each aggregated error is an uncaught exception/rejection, and debug info should provide as much details as possible about them.

@LiviaMedeiros LiviaMedeiros added feature request Issues that request new features to be added to Node.js. inspector Issues and PRs related to the V8 inspector protocol errors Issues and PRs related to JavaScript errors originated in Node.js core. labels Jul 1, 2022
nodejs-github-bot pushed a commit that referenced this issue Jul 9, 2022
PR-URL: #43646
Fixes: #43645
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
targos pushed a commit that referenced this issue Jul 12, 2022
PR-URL: #43646
Fixes: #43645
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
targos pushed a commit that referenced this issue Jul 31, 2022
PR-URL: #43646
Fixes: #43645
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
@SimenB
Copy link
Member

SimenB commented Aug 31, 2022

Would it be possible to make this nested/recurse?

(()=>{throw new AggregateError([new AggregateError([new TypeError('blep'), new RangeError('blop')], 'inner')],'gwak')})()
Uncaught AggregateError: gwak
    at REPL2:1:13 {
  [errors]: [
    AggregateError: inner
        at REPL2:1:33
        at REPL2:1:120
        at Script.runInThisContext (node:vm:129:12)
        at REPLServer.defaultEval (node:repl:572:29)
        at bound (node:domain:433:15)
        at REPLServer.runBound [as eval] (node:domain:444:12)
        at REPLServer.onLine (node:repl:902:10)
        at REPLServer.emit (node:events:525:35)
        at REPLServer.emit (node:domain:489:12)
        at REPLServer.Interface._onLine (node:readline:491:10) {
      [errors]: [Array]
    }
  ]
}

Notice [errors]: [Array]

@LiviaMedeiros
Copy link
Contributor Author

This is recursive, but the depth is limited by default.

> [[[123]]]
[ [ [ 123 ] ] ]

> [[[[123]]]]
[ [ [ [Array] ] ] ]

Inspecting explicitly:

> try {
(()=>{throw new AggregateError([new AggregateError([new TypeError('blep'), new RangeError('blop')], 'inner')],'gwak')})()
} catch(e) { console.log(util.inspect(e)) }

AggregateError: gwak
    at REPL34:1:19
    at REPL34:1:126
    at Script.runInThisContext (node:vm:129:12)
    at REPLServer.defaultEval (node:repl:572:29)
    at bound (node:domain:433:15)
    at REPLServer.runBound [as eval] (node:domain:444:12)
    at REPLServer.onLine (node:repl:902:10)
    at REPLServer.emit (node:events:525:35)
    at REPLServer.emit (node:domain:489:12)
    at [_onLine] [as _onLine] (node:internal/readline/interface:425:12) {
  [errors]: [
    AggregateError: inner
        at REPL34:1:39
        at REPL34:1:126
        at Script.runInThisContext (node:vm:129:12)
        at REPLServer.defaultEval (node:repl:572:29)
        at bound (node:domain:433:15)
        at REPLServer.runBound [as eval] (node:domain:444:12)
        at REPLServer.onLine (node:repl:902:10)
        at REPLServer.emit (node:events:525:35)
        at REPLServer.emit (node:domain:489:12)
        at [_onLine] [as _onLine] (node:internal/readline/interface:425:12) {
      [errors]: [Array]
    }
  ]
}

Inspecting with depth: 9:

> try {
(()=>{throw new AggregateError([new AggregateError([new TypeError('blep'), new RangeError('blop')], 'inner')],'gwak')})()
} catch(e) { console.log(util.inspect(e, { depth: 9 })) }

AggregateError: gwak
    at REPL37:1:19
    at REPL37:1:126
    at Script.runInThisContext (node:vm:129:12)
    at REPLServer.defaultEval (node:repl:572:29)
    at bound (node:domain:433:15)
    at REPLServer.runBound [as eval] (node:domain:444:12)
    at REPLServer.onLine (node:repl:902:10)
    at REPLServer.emit (node:events:525:35)
    at REPLServer.emit (node:domain:489:12)
    at [_onLine] [as _onLine] (node:internal/readline/interface:425:12) {
  [errors]: [
    AggregateError: inner
        at REPL37:1:39
        at REPL37:1:126
        at Script.runInThisContext (node:vm:129:12)
        at REPLServer.defaultEval (node:repl:572:29)
        at bound (node:domain:433:15)
        at REPLServer.runBound [as eval] (node:domain:444:12)
        at REPLServer.onLine (node:repl:902:10)
        at REPLServer.emit (node:events:525:35)
        at REPLServer.emit (node:domain:489:12)
        at [_onLine] [as _onLine] (node:internal/readline/interface:425:12) {
      [errors]: [
        TypeError: blep
            at REPL37:1:59
            at REPL37:1:126
            at Script.runInThisContext (node:vm:129:12)
            at REPLServer.defaultEval (node:repl:572:29)
            at bound (node:domain:433:15)
            at REPLServer.runBound [as eval] (node:domain:444:12)
            at REPLServer.onLine (node:repl:902:10)
            at REPLServer.emit (node:events:525:35)
            at REPLServer.emit (node:domain:489:12)
            at [_onLine] [as _onLine] (node:internal/readline/interface:425:12),
        RangeError: blop
            at REPL37:1:82
            at REPL37:1:126
            at Script.runInThisContext (node:vm:129:12)
            at REPLServer.defaultEval (node:repl:572:29)
            at bound (node:domain:433:15)
            at REPLServer.runBound [as eval] (node:domain:444:12)
            at REPLServer.onLine (node:repl:902:10)
            at REPLServer.emit (node:events:525:35)
            at REPLServer.emit (node:domain:489:12)
            at [_onLine] [as _onLine] (node:internal/readline/interface:425:12)
      ]
    }
  ]
}

@SimenB
Copy link
Member

SimenB commented Aug 31, 2022

Right, my point was more if it could work by default for console.log etc without the depth argument?

guangwong pushed a commit to noslate-project/node that referenced this issue Oct 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
errors Issues and PRs related to JavaScript errors originated in Node.js core. feature request Issues that request new features to be added to Node.js. inspector Issues and PRs related to the V8 inspector protocol
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants