-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
23 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,12 @@ | ||
import { findFormat } from './formats/main.js' | ||
|
||
// Enhances delta error messages | ||
export const addDeltaError = function (error, { type, delta, name }) { | ||
const deltaError = getDeltaError({ type, delta, name }) | ||
error.message = `${deltaError} ${error.message}` | ||
return error | ||
} | ||
|
||
export const getDeltaError = function ({ type, delta, name }) { | ||
const { message } = findFormat(type) | ||
const deltaProp = getDeltaProp(delta, name) | ||
return `${deltaProp} (${message})` | ||
const typeMessage = getDeltaTypeMessage(type) | ||
return `Configuration property "${name}" with value "${delta}" (${typeMessage})` | ||
} | ||
|
||
export const getDeltaProp = function (delta, name) { | ||
return `"${name}" configuration property "${delta}"` | ||
export const getDeltaTypeMessage = function (type) { | ||
const { message } = findFormat(type) | ||
return message | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,35 @@ | ||
import { UserError } from '../../error/main.js' | ||
import { wrapError } from '../../error/wrap.js' | ||
import { findValue } from '../../utils/find.js' | ||
|
||
import { getDeltaProp, addDeltaError } from './error.js' | ||
import { getDeltaTypeMessage } from './error.js' | ||
import { FORMATS } from './formats/main.js' | ||
|
||
// Several configuration properties targets a previous rawResult using a delta, | ||
// which can an integer, "first", date/time/duration, rawResult.id or git | ||
// reference. | ||
export const transformDelta = function (delta, { name }) { | ||
if (delta === '') { | ||
const deltaProp = getDeltaProp(delta, name) | ||
throw new UserError(`${deltaProp} must not be an empty string`) | ||
throw new UserError('must not be an empty string.') | ||
} | ||
|
||
const deltaReturn = findValue(FORMATS, (format) => | ||
parseDelta({ format, delta, name }), | ||
) | ||
const deltaReturn = findValue(FORMATS, (format) => parseDelta(format, delta)) | ||
|
||
if (deltaReturn === undefined) { | ||
const deltaProp = getDeltaProp(delta, name) | ||
throw new UserError( | ||
`${deltaProp} must be an integer, "first", a date/time/duration, a result id or a git commit/tag/branch.`, | ||
'must be an integer, "first", a date/time/duration, a result id or a git commit/tag/branch.', | ||
) | ||
} | ||
|
||
const { type, value } = deltaReturn | ||
return { type, value, delta, name } | ||
} | ||
|
||
const parseDelta = function ({ format: { parse, type }, delta, name }) { | ||
const parseDelta = function ({ parse, type }, delta) { | ||
try { | ||
const value = parse(delta) | ||
return value === undefined ? undefined : { type, value } | ||
} catch (error) { | ||
throw addDeltaError(error, { type, delta, name }) | ||
throw wrapError(error, getDeltaTypeMessage(type)) | ||
} | ||
} |