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

keep origin js exception info in error #654

Closed
hardfist opened this issue Jan 7, 2021 · 0 comments
Closed

keep origin js exception info in error #654

hardfist opened this issue Jan 7, 2021 · 0 comments

Comments

@hardfist
Copy link
Contributor

hardfist commented Jan 7, 2021

It seems that esbuild will convert js exception info in plugin to string,which is inconvenient to do some logging according to the exception message。

import esbuild from 'esbuild';

const {build} = esbuild
class MyException {
  constructor(code, message,detail){
    this.code = code;
    this.message = message;
    this.detail = detail
  }
}
async function mybuild() {
  const result = await build({
    entryPoints: ['./src/index.js'],
    bundle: true,
    sourcemap:true,
    write:false,
    format: 'esm',
    plugins: [{
      name: 'esbuild',
      setup(build){
        build.onResolve({filter: /.*/},() => {
          throw new MyException(10086, 'encode error', {a:1,b:2})
        })
      }
    }]
  })
}
async function main(){
  try {
    await mybuild();
  }catch(err){
    console.log('myerr:', err.message, err.errors[0])
  }
}

main();

which generate the following error info
image

it would be helpful to adding the origin serialized exception in the error,something like

errors: [{
  location: null,
  text: '[esbuild] encode error',
  originInfo: JSON.stringify(myexception)
}]

which we could parse the originInfo to get originException, so as to do some business logic according to exception

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

Successfully merging a pull request may close this issue.

1 participant