evanw / evanw/esbuild

The `onEnd()` callback is returning incorrect error information, specifically showing "Detail: 0."

Open
#3,948 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
40.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

Hi,

Thank you for your hard work in making this amazing bundler perfectly and efficiently.

Could you please look into why the `onEnd()` callback isn't handling errors properly? It only returns `text`, while everything else is omitted.

The same works as expected in onStart, onResolve and onLoad callbacks.

```ts
import * as esbuild from 'esbuild-wasm'

class CustomError extends Error {
detail: any
location: any
id: string
constructor(message: string) {
super(message)
this.name = 'CustomError'
this.detail = {
code: 'CUSTOM_CODE',
}
this.location = null
this.id = '123'
}
}

;(async () => {
await esbuild.initialize({
wasmURL: './node_modules/esbuild-wasm/esbuild.wasm',
})

try {
await esbuild.build({
stdin: {
contents: 'console.log(123)',
sourcefile: '/index.js',
resolveDir: '/',
},
plugins: [
{
name: 'test',
setup(build) {
build.onEnd(() => {
throw new CustomError('hello')
// Return {errors: [...]} // it will not work as well
})
},
},
],
})
} catch (err) {
console.log(JSON.stringify(err.errors, null, 2))
// Prints
/**
[
{
"id": "",
"pluginName": "test",
"text": "hello",
"location": null,
"notes": [],
"detail": 0
}
]
*/
}
})()

```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the esbuild-wasm build.onEnd callback in the provided reproduction, then compare its error handling with onStart, onResolve, and onLoad. Run the example and inspect the resulting err.errors output; the issue is resolved when the onEnd error preserves fields such as detail, location, and id instead of returning detail 0.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, typescript, wasm
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.