Skip to content

Commit

Permalink
Improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Jan 23, 2022
1 parent 65b020b commit 09cf169
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/config/normalize/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// eslint-disable-next-line no-restricted-imports, node/no-restricted-import
import { AssertionError } from 'assert'

import { wrapError } from '../../error/wrap.js'

import { normalizeConfigProps } from './lib/main.js'
import { DEFINITIONS } from './prop_defs.js'

Expand Down Expand Up @@ -32,7 +34,9 @@ const safeNormalizeConfig = async function (config, context, ErrorType) {

// `AssertionErrors` are user-validation errors. Others are system errors.
const handleConfigError = function (error, ErrorType) {
return error instanceof AssertionError ? new ErrorType(error.message) : error
return error instanceof AssertionError
? wrapError(error, '', ErrorType)
: error
}

// Perform normalization that is difficult to do with the main configuration
Expand Down
2 changes: 1 addition & 1 deletion src/error/wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const changeErrorType = function (error, ErrorType) {
return newError
}

// Prepend a prefix to an error message
// Prepend|append a prefix|suffix to an error message
const wrapErrorMessage = function (error, message) {
if (message === '') {
return error
Expand Down

0 comments on commit 09cf169

Please sign in to comment.