Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report debug_key/debug_reporting issues as warnings #1466

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion ts/src/header-validator/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class Context {
warnings: [],
notes: [],
}
errorAsWarning: boolean = false

scope<T>(c: PathComponent, f: () => T): T {
this.path.push(c)
Expand All @@ -31,7 +32,11 @@ export class Context {
}

error(msg: string): void {
this.result.errors.push(this.issue(msg))
if (this.errorAsWarning) {
this.warning(msg)
} else {
this.result.errors.push(this.issue(msg))
}
}

warning(msg: string): void {
Expand Down
6 changes: 3 additions & 3 deletions ts/src/header-validator/source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ const testCases: TestCase[] = [
"destination": "https://a.test",
"debug_key": 1
}`,
expectedErrors: [
expectedWarnings: [
{
path: ['debug_key'],
msg: 'must be a string',
Expand All @@ -635,7 +635,7 @@ const testCases: TestCase[] = [
"destination": "https://a.test",
"debug_key": "-1"
}`,
expectedErrors: [
expectedWarnings: [
{
path: ['debug_key'],
msg: 'string must represent a non-negative integer (must match /^[0-9]+$/)',
Expand Down Expand Up @@ -1071,7 +1071,7 @@ const testCases: TestCase[] = [
"destination": "https://a.test",
"debug_reporting": "true"
}`,
expectedErrors: [
expectedWarnings: [
{
path: ['debug_reporting'],
msg: 'must be a boolean',
Expand Down
6 changes: 3 additions & 3 deletions ts/src/header-validator/trigger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ const testCases: jsontest.TestCase<Trigger>[] = [
{
name: 'debug-reporting-wrong-type',
input: `{"debug_reporting": "true"}`,
expectedErrors: [
expectedWarnings: [
{
path: ['debug_reporting'],
msg: 'must be a boolean',
Expand All @@ -525,7 +525,7 @@ const testCases: jsontest.TestCase<Trigger>[] = [
{
name: 'debug-key-wrong-type',
input: `{"debug_key": 1}`,
expectedErrors: [
expectedWarnings: [
{
path: ['debug_key'],
msg: 'must be a string',
Expand All @@ -535,7 +535,7 @@ const testCases: jsontest.TestCase<Trigger>[] = [
{
name: 'debug-key-wrong-format',
input: `{"debug_key": "-1"}`,
expectedErrors: [
expectedWarnings: [
{
path: ['debug_key'],
msg: 'string must represent a non-negative integer (must match /^[0-9]+$/)',
Expand Down
19 changes: 17 additions & 2 deletions ts/src/header-validator/validate-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,24 @@ export function array<T, C extends Context = Context>(
)
}

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

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

export const priorityField: StructFields<Priority> = {
Expand Down
Loading