Skip to content

Commit

Permalink
Add error types for config normalization logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed May 29, 2022
1 parent 724666d commit 1029eab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/config/normalize/lib/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ export const DefinitionError = createErrorType('DefinitionError')
export const KeywordError = createErrorType('KeywordError')
// Bug in the library itself
export const CoreError = createErrorType('CoreError')

// All error types, with first being default type
export const ErrorTypes = [CoreError, InputError, DefinitionError, KeywordError]
14 changes: 9 additions & 5 deletions src/config/normalize/lib/main.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import pReduce from 'p-reduce'
import { list } from 'wild-wild-path'

import { allowErrorTypes } from '../../../error/types.js'
import { cleanObject } from '../../../utils/clean.js'

import { InputError } from './error.js'
import { InputError, ErrorTypes } from './error.js'
import { getInfo } from './info.js'
import { applyKeywords } from './keywords/main.js'
import { normalizeRules } from './normalize.js'
Expand Down Expand Up @@ -35,8 +36,7 @@ export const normalizeInputs = async function (inputs, rules, opts) {
logWarnings(warnings, soft)
return { inputs: inputsB, warnings }
} catch (error) {
handleError(error, soft)
return { error, warnings: [] }
return handleError(error, soft)
}
}

Expand Down Expand Up @@ -79,7 +79,11 @@ const applyEntryRule = async function (
// When in `sort` mode, user errors are returned instead of being thrown.
// System errors are always propagated.
const handleError = function (error, soft) {
if (!soft || !(error instanceof InputError)) {
throw error
const errorA = allowErrorTypes(error, ErrorTypes)

if (!soft || !(errorA instanceof InputError)) {
throw errorA
}

return { error: errorA, warnings: [] }
}

0 comments on commit 1029eab

Please sign in to comment.