From db415c95196965bef5a4351b0e9a689aaae4783d Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 17 May 2019 23:45:14 +0200 Subject: [PATCH] fix: throw new error object so stack traces are valid 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. --- src/index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 3d6d9a6..d19a3de 100644 --- a/src/index.js +++ b/src/index.js @@ -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. * @@ -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()) {