- Notifications
You must be signed in to change notification settings - Fork0
Properly update an error's stack.
License
ehmicky/set-error-stack
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
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.
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'
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.
errorError | anystackstring
Return value:Error
Setserror.stack = stack. If needed, also modifieserror.messageaccordingly.
Returnserror. Iferror is not anError instance, it is converted to one.
modern-errors: Handle errors ina simple, stable, consistent wayerror-custom-class: Createone error classerror-class-utils: Utilitiesto properly create error classeserror-serializer: Converterrors to/from plain objectsnormalize-exception:Normalize exceptions/errorsis-error-instance: Check ifa value is anErrorinstancemerge-error-cause: Merge anerror with itscauseset-error-class: Properlyupdate an error's classset-error-message: Properlyupdate an error's messagewrap-error-message:Properly wrap an error's messageset-error-props: Properlyupdate an error's propertieserror-cause-polyfill:Polyfillerror.causehandle-cli-error: 💣 Errorhandler for CLI applications 💥beautiful-error: Prettifyerror messages and stackslog-process-errors: Showsome ❤ to Node.js process errorserror-http-response:Create HTTP error responseswinston-error-format: Logerrors with Winston
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.
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!
About
Properly update an error's stack.
Topics
Resources
License
Code of conduct
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.