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 147d2f8 commit 86a2e90
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
22 changes: 22 additions & 0 deletions lib/definitions/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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 = {
EINVALIDASSETS: ({assets}) => ({
message: 'Invalid `assets` option.',
details: `The [assets option](${linkify(
'README.md#assets'
)}) option must be an \`Array\` of \`Strings\` or \`Objects\` with a \`path\` property.
Your configuration for the \`assets\` option is \`${assets}\`.`,
}),
EINVALIDMESSAGE: ({message}) => ({
message: 'Invalid `message` option.',
details: `The [message option](${linkify('README.md#message')}) option, if defined, must be a non empty \`String\`.
Your configuration for the \`successComment\` option is \`${message}\`.`,
}),
};
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);
};
13 changes: 3 additions & 10 deletions lib/verify.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const {isString, isUndefined, isArray, isPlainObject} = require('lodash');
const AggregateError = require('aggregate-error');
const SemanticReleaseError = require('@semantic-release/error');
const getError = require('./get-error');
const resolveConfig = require('./resolve-config');

/**
Expand All @@ -24,18 +24,11 @@ module.exports = async pluginConfig => {
assets.every(asset => isStringOrStringArray(asset) || (isPlainObject(asset) && isStringOrStringArray(asset.path)))
)
) {
errors.push(
new SemanticReleaseError(
'The "assets" options must be an Array of Strings or Objects with a path property.',
'EINVALIDASSETS'
)
);
errors.push(getError('EINVALIDASSETS', {assets}));
}

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

if (errors.length > 0) {
Expand Down

0 comments on commit 86a2e90

Please sign in to comment.