Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Properly update an error's stack.

License

NotificationsYou must be signed in to change notification settings

ehmicky/set-error-stack

NodeBrowsersTypeScriptCodecovMinified sizeMastodonMedium

Properly update an error's stack.

In V8 (Chrome, Node.js, Deno, etc.),error.stackincludeserror.message.However, iferror.stack is modified,error.message is not updatedaccordingly. This library fixes it.

In other JavaScript engines, this library just setserror.stack.

Example

Withoutset-error-stack:

consterror=newError('one')console.log(error.stack)// 'Error: one ...'console.log(error.message)// 'one'error.stack=error.stack.replace('one','two')console.log(error.stack)// 'Error: two ...'console.log(error.message)// 'one'

Withset-error-stack:

importsetErrorStackfrom'set-error-stack'consterror=newError('one')console.log(error.stack)// 'Error: one ...'console.log(error.message)// 'one'setErrorStack(error,error.stack.replace('one','two'))console.log(error.stack)// 'Error: two ...'console.log(error.message)// 'two'

Install

npm install set-error-stack

This package works in both Node.js >=18.18.0 andbrowsers.

This is an ES module. It must be loaded usinganimport orimport() statement,notrequire(). If TypeScript is used, it must be configured tooutput ES modules,not CommonJS.

API

setErrorStack(error, stack)

errorError | any
stackstring
Return value:Error

Setserror.stack = stack. If needed, also modifieserror.messageaccordingly.

Returnserror. Iferror is not anError instance, it is converted to one.

Related projects

Support

For any question,don't hesitate tosubmit an issue on GitHub.

Everyone is welcome regardless of personal background. We enforce aCode of conduct in order to promote a positive andinclusive environment.

Contributing

This project was made with ❤️. The simplest way to give back is by starring andsharing it online.

If the documentation is unclear or has a typo, please click on the page'sEditbutton (pencil icon) and suggest a correction.

If you would like to help us fix a bug or add a new feature, please check ourguidelines. Pull requests are welcome!


[8]ページ先頭

©2009-2025 Movatter.jp