From 911835208a383598f42e5b57e771ca964e618ac3 Mon Sep 17 00:00:00 2001 From: missinglink Date: Mon, 13 Sep 2021 17:58:21 +0200 Subject: [PATCH] feat(errors): throw instances of Error --- index.js | 6 +++--- test/index.js | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 4978cbe..4a54139 100644 --- a/index.js +++ b/index.js @@ -42,7 +42,7 @@ module.exports = () => { return _.cloneDeep(levels); } - throw `unsupported log level: ${level}`; + throw new Error(`unsupported log level: ${level}`); }, isMessage: (level, pattern) => { if (levels.hasOwnProperty(level)) { @@ -51,10 +51,10 @@ module.exports = () => { _.isRegExp(pattern) ? message.match(pattern) : message === pattern); } - throw 'pattern must be a regexp or string'; + throw new Error('pattern must be a regexp or string'); } - throw `unsupported log level: ${level}`; + throw new Error(`unsupported log level: ${level}`); } }; diff --git a/test/index.js b/test/index.js index 0c912cf..689f9df 100644 --- a/test/index.js +++ b/test/index.js @@ -165,7 +165,7 @@ test('unknown level parameter to getMessages should throw error', (t) => { t.throws( rootLogger.getMessages.bind(null, 'unknown level'), - /^unsupported log level: unknown level$/ + /^Error: unsupported log level: unknown level$/ ); t.end(); @@ -220,7 +220,7 @@ test('unknown level parameter to hasMessages should throw error', (t) => { t.throws( rootLogger.hasMessages.bind(null, 'unknown level'), - /^unsupported log level: unknown level$/ + /^Error: unsupported log level: unknown level$/ ); t.end(); @@ -281,11 +281,11 @@ test('isMessage should throw an error if the supplied pattern is not a valid reg rootLogger.getLevels().forEach((level) => { t.throws( rootLogger.isMessage.bind(null, level, 17.3), - /^pattern must be a regexp or string$/ + /^Error: pattern must be a regexp or string$/ ); t.throws( rootLogger[`is${_.capitalize(level)}Message`].bind(null, 17.3), - /^pattern must be a regexp or string$/ + /^Error: pattern must be a regexp or string$/ ); }); @@ -298,7 +298,7 @@ test('unknown level parameter to isMessage should throw error', (t) => { t.throws( rootLogger.isMessage.bind(null, 'unknown level'), - /^unsupported log level: unknown level$/ + /^Error: unsupported log level: unknown level$/ ); t.end();