Skip to content

Commit

Permalink
Return effective value when error is warning (#1468)
Browse files Browse the repository at this point in the history
  • Loading branch information
apasel422 authored Nov 16, 2024
1 parent bc4f4cc commit 40ef03f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions ts/src/header-validator/validate-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,22 +244,26 @@ export function array<T, C extends Context = Context>(
}

function withErrorAsWarning<C extends Context, I, O>(
f: CtxFunc<C, I, O>
): CtxFunc<C, I, O> {
f: CtxFunc<C, I, Maybe<O>>,
valueIfError: O
): CtxFunc<C, I, Maybe<O>> {
return (i, ctx) => {
const prev = ctx.errorAsWarning
ctx.errorAsWarning = true
const result = f(i, ctx)
ctx.errorAsWarning = prev
return result
return result.value === undefined ? Maybe.some(valueIfError) : result
}
}

export const commonDebugFields: StructFields<CommonDebug> = {
debugKey: field('debug_key', withDefault(withErrorAsWarning(uint64), null)),
debugKey: field(
'debug_key',
withDefault(withErrorAsWarning(uint64, null), null)
),
debugReporting: field(
'debug_reporting',
withDefault(withErrorAsWarning(bool), false)
withDefault(withErrorAsWarning(bool, false), false)
),
}

Expand Down

0 comments on commit 40ef03f

Please sign in to comment.