Skip to content

Commit

Permalink
feat: add details to error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg authored and gr2m committed Feb 12, 2018
1 parent 5755ce7 commit 4a28f2e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
16 changes: 16 additions & 0 deletions lib/definitions/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const url = require('url');
const pkg = require('../../package.json');

const homepage = url.format({...url.parse(pkg.homepage), ...{hash: null}});
const linkify = file => `${homepage}/blob/master/${file}`;

module.exports = {
EINVALIDCHANGELOGFILE: ({changelogFile}) => ({
message: 'Invalid `changelogFile` option.',
details: `The [changelogFile option](${linkify(
'README.md#changelogfile'
)}) option, if defined, must be a non empty \`String\`.
Your configuration for the \`assets\` option is \`${changelogFile}\`.`,
}),
};
7 changes: 7 additions & 0 deletions lib/get-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const SemanticReleaseError = require('@semantic-release/error');
const ERROR_DEFINITIONS = require('./definitions/errors');

module.exports = (code, ctx) => {
const {message, details} = ERROR_DEFINITIONS[code](ctx);
return new SemanticReleaseError(message, code, details);
};
9 changes: 2 additions & 7 deletions lib/verify.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
const {isString, isUndefined} = require('lodash');
const AggregateError = require('aggregate-error');
const SemanticReleaseError = require('@semantic-release/error');
const getError = require('./get-error');
const resolveConfig = require('./resolve-config');

module.exports = pluginConfig => {
const {changelogFile} = resolveConfig(pluginConfig);
const errors = [];

if (!isUndefined(changelogFile) && !(isString(changelogFile) && changelogFile.trim())) {
errors.push(
new SemanticReleaseError(
'The "changelogFile" options, if defined, must be a non empty String.',
'EINVALIDCHANGELOGFILE'
)
);
errors.push(getError('EINVALIDCHANGELOGFILE', {changelogFile}));
}

if (errors.length > 0) {
Expand Down

0 comments on commit 4a28f2e

Please sign in to comment.