Skip to content

Commit

Permalink
fix: remove reason from unparsable file error and add to messages
Browse files Browse the repository at this point in the history
  • Loading branch information
evaline-ju committed Nov 19, 2020
1 parent b4dcc6c commit fcc005c
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 10 deletions.
5 changes: 4 additions & 1 deletion lib/cli/config.js
Expand Up @@ -83,7 +83,10 @@ exports.loadConfig = filepath => {
config = parsers.json(filepath);
}
} catch (err) {
throw createUnparsableFileError(err, filepath);
throw createUnparsableFileError(
`Unable to read/parse ${filepath}: ${err}`,
filepath
);
}
return config;
};
Expand Down
5 changes: 4 additions & 1 deletion lib/cli/options.js
Expand Up @@ -190,7 +190,10 @@ const loadPkgRc = (args = {}) => {
}
} catch (err) {
if (args.package) {
throw createUnparsableFileError(err, filepath);
throw createUnparsableFileError(
`Unable to read/parse ${filepath}: ${err}`,
filepath
);
}
debug('failed to read default package.json at %s; ignoring', filepath);
}
Expand Down
5 changes: 1 addition & 4 deletions lib/errors.js
Expand Up @@ -508,14 +508,11 @@ function createTimeoutError(msg, timeout, file) {
* @static
* @param {string} message - Error message to be displayed.
* @param {string} filename - File name
* @param {string} [reason] - Why the filename is unparsable.
* @returns {Error} Error with code {@link constants.UNPARSABLE_FILE}
*/
function createUnparsableFileError(message, filename, reason) {
function createUnparsableFileError(message, filename) {
var err = new Error(message);
err.code = constants.UNPARSABLE_FILE;
err.reason =
typeof reason !== 'undefined' ? reason : `${filename} is unparsable`;
return err;
}

Expand Down
2 changes: 1 addition & 1 deletion test/node-unit/cli/config.spec.js
Expand Up @@ -116,7 +116,7 @@ describe('cli/config', function() {
expect(
() => loadConfig('goo.yaml'),
'to throw',
'goo.yaml is unparsable'
'Unable to read/parse goo.yaml: goo.yaml is unparsable'
);
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/node-unit/cli/options.spec.js
Expand Up @@ -150,7 +150,7 @@ describe('options', function() {
loadOptions('--package /something/wherever --require butts');
},
'to throw',
'bad file message'
'Unable to read/parse /something/wherever: bad file message'
);
});
});
Expand Down
3 changes: 1 addition & 2 deletions test/unit/errors.spec.js
Expand Up @@ -76,8 +76,7 @@ describe('Errors', function() {
'to satisfy',
{
message: message,
code: 'ERR_MOCHA_UNPARSABLE_FILE',
reason: 'badFilePath is unparsable'
code: 'ERR_MOCHA_UNPARSABLE_FILE'
}
);
});
Expand Down

0 comments on commit fcc005c

Please sign in to comment.