From 4a28f2efc9e01f74c8d3e7b3e27827ead34331e1 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Sun, 11 Feb 2018 17:57:49 -0500 Subject: [PATCH] feat: add `details` to error messages --- lib/definitions/errors.js | 16 ++++++++++++++++ lib/get-error.js | 7 +++++++ lib/verify.js | 9 ++------- 3 files changed, 25 insertions(+), 7 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..e92d7c99 --- /dev/null +++ b/lib/definitions/errors.js @@ -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}\`.`, + }), +}; 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 28fa6ce0..d942de51 100644 --- a/lib/verify.js +++ b/lib/verify.js @@ -1,6 +1,6 @@ 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 => { @@ -8,12 +8,7 @@ module.exports = 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) {