Skip to content

Commit

Permalink
api: reduce console output when an error is thrown
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Aug 9, 2023
1 parent ab9007c commit 813fb3a
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions lib/shared/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1653,17 +1653,34 @@ function parseStackLinesV8(streamIn: StreamIn, lines: string[], ident: string):

function failureErrorWithLog(text: string, errors: types.Message[], warnings: types.Message[]): types.BuildFailure {
let limit = 5
let summary = errors.length < 1 ? '' : ` with ${errors.length} error${errors.length < 2 ? '' : 's'}:` +
text += errors.length < 1 ? '' : ` with ${errors.length} error${errors.length < 2 ? '' : 's'}:` +
errors.slice(0, limit + 1).map((e, i) => {
if (i === limit) return '\n...'
if (!e.location) return `\nerror: ${e.text}`
let { file, line, column } = e.location
let pluginText = e.pluginName ? `[plugin: ${e.pluginName}] ` : ''
return `\n${file}:${line}:${column}: ERROR: ${pluginText}${e.text}`
}).join('')
let error: any = new Error(`${text}${summary}`)
error.errors = errors
error.warnings = warnings
let error: any = new Error(text)

// Use a getter instead of a plain property so that when the error is thrown
// without being caught and the node process exits, the error objects aren't
// printed. The error objects are pretty big and not helpful because a) esbuild
// already prints errors to stderr by default and b) the error summary already
// has a more helpful abbreviated form of the error messages.
for (const [key, value] of [['errors', errors], ['warnings', warnings]] as const) {
Object.defineProperty(error, key, {
configurable: true,
enumerable: true,
get: () => value,
set: value => Object.defineProperty(error, key, {
configurable: true,
enumerable: true,
value,
}),
})
}

return error
}

Expand Down

0 comments on commit 813fb3a

Please sign in to comment.