Answer the architecture pass: one fault vocabulary, and the guards pinned where they compose
CI / gate (push) Successful in 5s
CI / gate (push) Successful in 5s
This commit is contained in:
+7
-2
@@ -18,12 +18,13 @@ export type ConvertErrorCode =
|
||||
|
||||
export type ConvertErrorPath = readonly (number | string)[]
|
||||
|
||||
export type ConvertFault = {
|
||||
export type ConvertError = {
|
||||
code: ConvertErrorCode
|
||||
message: string
|
||||
path: ConvertErrorPath
|
||||
}
|
||||
|
||||
export type ConvertError = ConvertFault & { path: ConvertErrorPath }
|
||||
export type ConvertFault = Omit<ConvertError, 'path'>
|
||||
|
||||
export type Result<T> = { error: ConvertError; ok: false } | { ok: true; value: T }
|
||||
|
||||
@@ -31,6 +32,10 @@ export function failure<T>(code: ConvertErrorCode, message: string, path: Conver
|
||||
return { error: { code, message, path }, ok: false }
|
||||
}
|
||||
|
||||
export function faulted<T>(fault: ConvertFault, path: ConvertErrorPath): Result<T> {
|
||||
return failure(fault.code, fault.message, path)
|
||||
}
|
||||
|
||||
export function success<T>(value: T): Result<T> {
|
||||
return { ok: true, value }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user