Skip to content

Surface gojq runtime errors instead of treating them as results#214

Open
damilolaedwards wants to merge 1 commit into
ethpandaops:masterfrom
damilolaedwards:fix-vars-jq-error-handling
Open

Surface gojq runtime errors instead of treating them as results#214
damilolaedwards wants to merge 1 commit into
ethpandaops:masterfrom
damilolaedwards:fix-vars-jq-error-handling

Conversation

@damilolaedwards

Copy link
Copy Markdown

Problem

gojq returns runtime evaluation errors (type errors, wrong-type indexing, division by zero, context timeout) as values of type error, with the iterator reporting ok == true. ResolveQuery and ConsumeVars read that value without checking its type, so an erroring query was treated as a successful result.

Consequences:

  • In the task if: path, the erroring condition became a non-boolean value, so the boolean assertion failed and the task was silently skipped instead of failing. A check that should have run (and might have failed) was quietly dropped and the run stayed green.
  • In ConsumeVars, the error object was marshalled into the task config, corrupting the consumed value.

Fix

After reading the query result, type assert it against error and return the error in both ResolveQuery and ConsumeVars. A failed condition or config query now surfaces loudly, the same way a parse error already did, instead of being hidden.

Tests

An erroring query (adding a number to a string) now returns an error from both functions and does not leak the error value as a result; valid queries still resolve normally.

go build ./..., go vet, and the vars package tests pass.

gojq returns a runtime evaluation error (type error, wrong type, division
by zero, and so on) as a value with ok true. ResolveQuery and ConsumeVars
read that value without checking its type, so an erroring query was
reported as a successful result. In the task if condition path this made
the condition a non boolean value and the task was silently skipped rather
than failing; in ConsumeVars the error object was written into the task
config. Type assert the result and return the error in both places.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant