Skip to content

fix(transformation): report a failed transformation run as a failure - #417

Merged
leggetter merged 1 commit into
feat/api-2026-09-01from
fix/transformation-run-failure
Sep 15, 2026
Merged

leggetter merged 1 commit into
feat/api-2026-09-01from
fix/transformation-run-failure

Conversation

@leggetter

Copy link
Copy Markdown
Collaborator

Closes #410. Stacked on #378 (base: feat/api-2026-09-01).

gateway transformation run reported success for every kind of failure:

hookdeck gateway transformation run \
  --code 'addHandler("transform",(r,c)=>{ throw new Error("boom"); });' \
  --request '{"headers":{}}' --output json
→ {}
→ exit 0

Same {} and exit 0 for invalid JavaScript and a nonexistent --id. Console output was never surfaced. Testing a transformation before shipping it is this command's whole purpose, and it could not report that the code was broken.

Root cause

PUT /transformations/run answers HTTP 200 whether the code ran or threw. A throwing handler returns:

{"log_level": "fatal", "console": [ ]}

with no request key. TransformationRunResponse declared neither log_level nor console, so the body parsed into an empty struct, printed {}, and returned nil.

The fix was already written

release/v3.0.0 already contains this fix, with comments naming the exact symptom. Rather than reinvent it, this ports the relevant half.

Deliberately left behind: the apiPath(...) refactor across GetTransformation, UpdateTransformation, DeleteTransformation, ListTransformationExecutions and GetTransformationExecution — that is v3.0.0's own path-escaping work, accounts for most of the upstream diff's size, touches nothing #410 runs through, and apiPath does not exist on this branch. Also left behind: unrelated struct churn and the eight other transformation_*.go files v3.0.0 touches.

Ignoring whitespace the change is 82 lines (61 model, 21 command) with 282 lines of tests. The remaining diff is gofmt realignment: both files were already gofmt-dirty at HEAD, and adding fields could not leave them clean without realigning their siblings.

One correction to the ported text: v3.0.0's doc comment claimed "fatal" and "error" mean the code did not complete, contradicting the Failed() implementation three lines below it. Rewritten to match verified behaviour — error is a successful run that logged an error, and its diagnostics now reach the user instead of being hidden.

Verified live, both directions

Case Before After
Throwing handler exit 0 exit 1
Throwing, --output json exit 0 exit 1 (payload still printed)
Invalid JavaScript exit 0 exit 1
Working transformation exit 0 exit 0
Logs an error, still returns exit 0, console surfaced

That last row is why Failed() keys on fatal alone: a handler that logs an error and returns anyway is a success, and is exactly the run someone is debugging.

Tests

Seven revert-checks, each reverted alone and restored: the json tags (the original defect), both Failed() call sites, console-on-success, and Failed() made both too broad (|| LogLevel == "error") and too narrow (dropping || Request == nil). Each failed the expected test.

Also adds TestTransformationRunThrowingHandlerFails to test/acceptance/transformation_test.go (tag transformation, CI slice 2) — an acceptance case of this shape would have caught the bug originally.

Follow-up worth filing

A nonexistent --id now exits 1, but the message is opaque: the API executes undefined as code, so the user sees a TypeError rather than "transformation not found". Server-side behaviour, outside this fix's scope.


🤖 Generated with Claude Code

https://claude.ai/code/session_01BnrKWZQASV7bFJ4oGWwmo9

…410)

`gateway transformation run` printed "{}" and exited 0 for every kind of
failure - a throwing handler, invalid JavaScript, a nonexistent --id.
Testing a transformation before shipping it is the command's entire
purpose, and it could not report that the code was broken.

PUT /transformations/run answers HTTP 200 whether the code ran or threw;
only the body differs. A throwing handler returns
{"log_level":"fatal","console":[...]} with no "request" at all.
TransformationRunResponse declared neither log_level nor console, so that
body parsed into an empty struct - hence the "{}" and the nil error.

Add LogLevel and Console to the response, a Failed() predicate and a
ConsoleText() renderer, and check Failed() on both the human and the
--output json paths. --output json still prints the payload before it
fails, because the console output is the diagnosis a script wants.

Failed() keys off log_level == "fatal" or a missing request, not off
log_level != "info": log_level is the highest severity the run logged,
not a completion flag, so a handler that calls console.error and then
returns a transformed request succeeded. Console output is now printed on
successful runs too - that handler is exactly the case someone is
debugging, and printing the console only on failure hid it.

Ported from release/v3.0.0. The unrelated apiPath() path-escaping refactor
in that branch's version of transformations.go is deliberately left behind.

Unit tests cover the predicate, the renderer, and all four command paths;
acceptance tests (tag: transformation) pin that a throwing handler exits
non-zero on both output paths.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BnrKWZQASV7bFJ4oGWwmo9
@leggetter
leggetter merged commit 61e6cdc into feat/api-2026-09-01 Sep 15, 2026
2 checks passed
@leggetter
leggetter deleted the fix/transformation-run-failure branch September 15, 2026 08:08
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