Skip to content

Commit 40ef03f

Browse files
authored
Return effective value when error is warning (#1468)
1 parent bc4f4cc commit 40ef03f

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

ts/src/header-validator/validate-json.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,22 +244,26 @@ export function array<T, C extends Context = Context>(
244244
}
245245

246246
function withErrorAsWarning<C extends Context, I, O>(
247-
f: CtxFunc<C, I, O>
248-
): CtxFunc<C, I, O> {
247+
f: CtxFunc<C, I, Maybe<O>>,
248+
valueIfError: O
249+
): CtxFunc<C, I, Maybe<O>> {
249250
return (i, ctx) => {
250251
const prev = ctx.errorAsWarning
251252
ctx.errorAsWarning = true
252253
const result = f(i, ctx)
253254
ctx.errorAsWarning = prev
254-
return result
255+
return result.value === undefined ? Maybe.some(valueIfError) : result
255256
}
256257
}
257258

258259
export const commonDebugFields: StructFields<CommonDebug> = {
259-
debugKey: field('debug_key', withDefault(withErrorAsWarning(uint64), null)),
260+
debugKey: field(
261+
'debug_key',
262+
withDefault(withErrorAsWarning(uint64, null), null)
263+
),
260264
debugReporting: field(
261265
'debug_reporting',
262-
withDefault(withErrorAsWarning(bool), false)
266+
withDefault(withErrorAsWarning(bool, false), false)
263267
),
264268
}
265269

0 commit comments

Comments
 (0)