Skip to content

Commit

Permalink
feat(errors): throw instances of Error
Browse files Browse the repository at this point in the history
  • Loading branch information
missinglink committed Sep 13, 2021
1 parent b8b9dc9 commit 9118352
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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}`);
}
};

Expand Down
10 changes: 5 additions & 5 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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$/
);
});

Expand All @@ -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();

Expand Down

0 comments on commit 9118352

Please sign in to comment.