Skip to content

Commit

Permalink
Merge pull request #23 from pelias/throw_errors
Browse files Browse the repository at this point in the history
throw instances of Error
  • Loading branch information
missinglink authored Sep 13, 2021
2 parents b8b9dc9 + 9118352 commit 35507c7
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 35507c7

Please sign in to comment.