Skip to content
This repository was archived by the owner on Dec 19, 2025. It is now read-only.

Commit b980837

Browse files
committed
Fix error message discrepancy in node 16
1 parent 80dfc7a commit b980837

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

lib/scheme-mapper.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1+
function validate(obj) {
2+
if (! obj) {
3+
throw new Error('The object to map must not be falsy!');
4+
}
5+
}
6+
17
/**
28
* Maps a response object into the form described here:
39
* https://github.com/axelrindle/github-version-checker/wiki/API#releases
410
*
511
* @returns {ReleaseDescriptor}
612
*/
713
module.exports.release = obj => {
14+
validate(obj)
15+
816
return {
917
name: obj.name,
1018
tag: {
@@ -23,6 +31,8 @@ module.exports.release = obj => {
2331
* @returns {TagDescriptor}
2432
*/
2533
module.exports.tag = obj => {
34+
validate(obj)
35+
2636
return {
2737
name: obj.name
2838
}

test/test-scheme-mapper.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ test('scheme-mapper#release fails with invalid object', t => {
5050
const error = t.throws(() => {
5151
return schemeMapper.release(null);
5252
});
53-
t.is(error.message, 'Cannot read property \'name\' of null');
53+
t.is(error.message, 'The object to map must not be falsy!');
5454

5555
const error2 = t.throws(() => {
5656
return schemeMapper.release(undefined);
5757
});
58-
t.is(error2.message, 'Cannot read property \'name\' of undefined');
58+
t.is(error2.message, 'The object to map must not be falsy!');
5959
});
6060

6161
test('scheme-mapper#tag maps correctly', t => {
@@ -74,10 +74,10 @@ test('scheme-mapper#tag fails with invalid object', t => {
7474
const error = t.throws(() => {
7575
return schemeMapper.tag(null);
7676
});
77-
t.is(error.message, 'Cannot read property \'name\' of null');
77+
t.is(error.message, 'The object to map must not be falsy!');
7878

7979
const error2 = t.throws(() => {
8080
return schemeMapper.tag(undefined);
8181
});
82-
t.is(error2.message, 'Cannot read property \'name\' of undefined');
82+
t.is(error2.message, 'The object to map must not be falsy!');
8383
});

0 commit comments

Comments
 (0)