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

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

Open
ianberdin opened this issue Oct 22, 2024 · 0 comments

Comments

@ianberdin
Copy link

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.

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
        }
      ]
     */
  }
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant