From 86a2e90fbe080c1bee8f68fb0face6282ddce7d6 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Sat, 10 Feb 2018 15:02:37 -0500 Subject: [PATCH] feat: add `details` to error messages --- lib/definitions/errors.js | 22 ++++++++++++++++++++++ lib/get-error.js | 7 +++++++ lib/verify.js | 13 +++---------- 3 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 lib/definitions/errors.js create mode 100644 lib/get-error.js diff --git a/lib/definitions/errors.js b/lib/definitions/errors.js new file mode 100644 index 00000000..f77d0c28 --- /dev/null +++ b/lib/definitions/errors.js @@ -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}\`.`, + }), +}; diff --git a/lib/get-error.js b/lib/get-error.js new file mode 100644 index 00000000..c5b926e8 --- /dev/null +++ b/lib/get-error.js @@ -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); +}; diff --git a/lib/verify.js b/lib/verify.js index adfa9335..f393e75e 100644 --- a/lib/verify.js +++ b/lib/verify.js @@ -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'); /** @@ -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) {