Unverified Commit a4f8b179 authored by Ben Brook's avatar Ben Brook Committed by GitHub

Include `AggregateError.errors` in terminal output (#88999)

Co-authored-by: 's avatarbencmbrook <7354176+bencmbrook@users.noreply.github.com>
Co-authored-by: 's avatarCursor Agent <cursoragent@cursor.com>
parent 1c73ca5a
...@@ -451,13 +451,16 @@ function sourceMapError( ...@@ -451,13 +451,16 @@ function sourceMapError(
error: Error, error: Error,
inspectOptions: util.InspectOptions inspectOptions: util.InspectOptions
): Error { ): Error {
// Setting an undefined `cause` would print `[cause]: undefined`
const options = error.cause !== undefined ? { cause: error.cause } : undefined
// Create a new Error object with the source mapping applied and then use native // Create a new Error object with the source mapping applied and then use native
// Node.js formatting on the result. // Node.js formatting on the result.
const newError = const newError =
error.cause !== undefined error instanceof AggregateError
? // Setting an undefined `cause` would print `[cause]: undefined` ? // Preserve AggregateError's `errors` instance property
new Error(error.message, { cause: error.cause }) new AggregateError(error.errors, error.message, options)
: new Error(error.message) : new Error(error.message, options)
// TODO: Ensure `class MyError extends Error {}` prints `MyError` as the name // TODO: Ensure `class MyError extends Error {}` prints `MyError` as the name
newError.stack = parseAndSourceMap(error, inspectOptions) newError.stack = parseAndSourceMap(error, inspectOptions)
......
/* global AggregateError */
function logError() {
const error1 = new Error('Error 1')
const error2 = new TypeError('Error 2')
const rootError = new Error('Root error')
const aggregateError = new AggregateError(
[error1, error2],
'rsc-error-log-aggregate',
{ cause: rootError }
)
console.error(aggregateError)
}
export default function Page() {
logError()
return null
}
...@@ -199,6 +199,76 @@ describe('app-dir - server source maps', () => { ...@@ -199,6 +199,76 @@ describe('app-dir - server source maps', () => {
} }
}) })
it('logged errors include `[errors]` for AggregateError', async () => {
if (isNextDev) {
const outputIndex = next.cliOutput.length
await next.render('/rsc-error-log-aggregate')
await retry(() => {
expect(next.cliOutput.slice(outputIndex)).toContain(
'AggregateError: rsc-error-log-aggregate'
)
})
expect(normalizeCliOutput(next.cliOutput.slice(outputIndex))).toContain(
'AggregateError: rsc-error-log-aggregate' +
'\n at logError (app/rsc-error-log-aggregate/page.js:6:26)' +
'\n at Page (app/rsc-error-log-aggregate/page.js:15:3)' +
"\n 4 | const error2 = new TypeError('Error 2')" +
"\n 5 | const rootError = new Error('Root error')" +
'\n> 6 | const aggregateError = new AggregateError(' +
'\n | ^' +
'\n 7 | [error1, error2],' +
"\n 8 | 'rsc-error-log-aggregate'," +
'\n 9 | { cause: rootError } {' +
'\n [cause]: Error: Root error' +
'\n at logError (app/rsc-error-log-aggregate/page.js:5:21)' +
'\n at Page (app/rsc-error-log-aggregate/page.js:15:3)' +
"\n 3 | const error1 = new Error('Error 1')" +
"\n 4 | const error2 = new TypeError('Error 2')" +
"\n > 5 | const rootError = new Error('Root error')" +
'\n | ^' +
'\n 6 | const aggregateError = new AggregateError(' +
'\n 7 | [error1, error2],' +
"\n 8 | 'rsc-error-log-aggregate',," +
'\n [errors]: [' +
'\n Error: Error 1' +
'\n at logError (app/rsc-error-log-aggregate/page.js:3:18)' +
'\n at Page (app/rsc-error-log-aggregate/page.js:15:3)' +
'\n 1 | /* global AggregateError */' +
'\n 2 | function logError() {' +
"\n > 3 | const error1 = new Error('Error 1')" +
'\n | ^' +
"\n 4 | const error2 = new TypeError('Error 2')" +
"\n 5 | const rootError = new Error('Root error')" +
'\n 6 | const aggregateError = new AggregateError(,' +
'\n TypeError: Error 2' +
'\n at logError (app/rsc-error-log-aggregate/page.js:4:18)' +
'\n at Page (app/rsc-error-log-aggregate/page.js:15:3)' +
'\n 2 | function logError() {' +
"\n 3 | const error1 = new Error('Error 1')" +
"\n > 4 | const error2 = new TypeError('Error 2')" +
'\n | ^' +
"\n 5 | const rootError = new Error('Root error')" +
'\n 6 | const aggregateError = new AggregateError(' +
'\n 7 | [error1, error2],' +
'\n ]' +
'\n}'
)
} else {
if (isTurbopack) {
// TODO(veil): Sourcemap names
// TODO(veil): relative paths in production
expect(normalizeCliOutput(next.cliOutput)).toContain(
'(app/rsc-error-log-aggregate/page.js:6:26)'
)
expect(normalizeCliOutput(next.cliOutput)).toContain('[errors]:')
expect(normalizeCliOutput(next.cliOutput)).toContain('[cause]:')
} else {
// TODO(veil): line/column numbers are flaky in Webpack
}
}
})
it('stack frames are ignore-listed in ssr', async () => { it('stack frames are ignore-listed in ssr', async () => {
if (isNextDev) { if (isNextDev) {
const outputIndex = next.cliOutput.length const outputIndex = next.cliOutput.length
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment