Skip to content
This repository has been archived by the owner on Aug 24, 2021. It is now read-only.

Commit

Permalink
fix: throw new error object so stack traces are valid
Browse files Browse the repository at this point in the history
If the thrown error was not created where it's thrown, the stack
trace does not reflect where the error was thrown from making it
harder to debug problems.

This PR removes the cached error object and instead creates a new
one when required.
  • Loading branch information
achingbrain committed May 17, 2019
1 parent 1e1dcbc commit db415c9
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ exports.isEncoded = isEncoded
exports.names = Object.freeze(Object.keys(constants.names))
exports.codes = Object.freeze(Object.keys(constants.codes))

const errNotSupported = new Error('Unsupported encoding')

/**
* Create a new buffer with the multibase varint+code.
*
Expand Down Expand Up @@ -120,7 +118,7 @@ function getBase (nameOrCode) {
} else if (constants.codes[nameOrCode]) {
base = constants.codes[nameOrCode]
} else {
throw errNotSupported
throw new Error('Unsupported encoding')
}

if (!base.isImplemented()) {
Expand Down

0 comments on commit db415c9

Please sign in to comment.