fix(transformation): report a failed transformation run as a failure - #417
Merged
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #410. Stacked on #378 (base:
feat/api-2026-09-01).gateway transformation runreported success for every kind of failure: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/runanswers HTTP 200 whether the code ran or threw. A throwing handler returns:{"log_level": "fatal", "console": [ … ]}with no
requestkey.TransformationRunResponsedeclared neitherlog_levelnorconsole, so the body parsed into an empty struct, printed{}, and returned nil.The fix was already written
release/v3.0.0already contains this fix, with comments naming the exact symptom. Rather than reinvent it, this ports the relevant half.Deliberately left behind: the
apiPath(...)refactor acrossGetTransformation,UpdateTransformation,DeleteTransformation,ListTransformationExecutionsandGetTransformationExecution— that is v3.0.0's own path-escaping work, accounts for most of the upstream diff's size, touches nothing #410 runs through, andapiPathdoes not exist on this branch. Also left behind: unrelated struct churn and the eight othertransformation_*.gofiles 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 theFailed()implementation three lines below it. Rewritten to match verified behaviour —erroris a successful run that logged an error, and its diagnostics now reach the user instead of being hidden.Verified live, both directions
--output jsonThat last row is why
Failed()keys onfatalalone: 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, andFailed()made both too broad (|| LogLevel == "error") and too narrow (dropping|| Request == nil). Each failed the expected test.Also adds
TestTransformationRunThrowingHandlerFailstotest/acceptance/transformation_test.go(tagtransformation, CI slice 2) — an acceptance case of this shape would have caught the bug originally.Follow-up worth filing
A nonexistent
--idnow exits 1, but the message is opaque: the API executesundefinedas code, so the user sees aTypeErrorrather than "transformation not found". Server-side behaviour, outside this fix's scope.🤖 Generated with Claude Code
https://claude.ai/code/session_01BnrKWZQASV7bFJ4oGWwmo9