fix: show clear error and non-zero exit on non-JSON API responses#27
fix: show clear error and non-zero exit on non-JSON API responses#27ektasawant wants to merge 3 commits into
Conversation
|
Bugbot is not enabled for this team, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
apgiorgi
left a comment
There was a problem hiding this comment.
Reviewed and verified the guard against the OpenAPI spec (doit-api.yaml): the AVA askSync top-level error-under-200 shape is confirmed, and the conservative top-level-object scoping correctly avoids false-positives on the only other 2xx-with-error endpoint (/insights/v1/results, a top-level array). Build/vet/tests pass, all CI green. LGTM.
|
Bugbot is not enabled for this team, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
|
@apgiorgi , could you please review again? |
|
👋 @ektasawant — this is approved and CI is green, but the merge is blocked by a repo constraint rather than anything in the code. This repo only allows rebase-merge (squash and merge-commits are disabled), and GitHub refuses to rebase a branch that contains a merge commit. This branch has one — Easiest fix is to linearize your branch by rebasing onto git checkout fix/ekta/ava-non-json-error-CMP-44313
git fetch origin
git rebase origin/main
# If a conflict pops up it's the trivial one in main.go around installResponseGuard() /
# registerAgentFlags() ordering — keep installResponseGuard() first, then continue:
# git add main.go && git rebase --continue
git push --force-with-leaseAfter that the history is just your two real commits on top of |
c3e3529 to
54b833e
Compare
|
Bugbot is not enabled for this team, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Summary
Make
dcifail cleanly when the DoiT API returns a non-successful AVAaskSyncresponse instead of dumping raw HTML and exiting 0.
Relates to CMP-46498 (epic CMP-44313).
Background
dciwraps restish, which on a non-JSON body silently falls back to printing theraw bytes and derives its exit code purely from the HTTP status. Two AVA failure
modes slip through as a result:
(e.g. a 524 rendered as the DoiT maintenance page) — dumped as a wall of HTML.
askSynchas started streaming, a mid-generation failure returns anapplication error body under a locked 2xx status, which restish treats as
success (exit 0).
Changes
Adds a
dciResponseGuardthat wraps restish's response formatter:timeout/maintenance, HTTP status, trace id, retry/contact support) and exits
non-zero. Trace id is read from
Cf-Ray,X-Doit-Trace,X-Request-Id,X-Cloud-Trace-Context, orTraceparent.error→ still prints the structured error body(respecting
--output), then frames it as an error on stderr and forces anon-zero exit.
Scope note
The formatter seam has no access to the request URL, so the JSON-
errorcheck isglobal rather than AVA-only. It's intentionally conservative — it fires only on a
2xx body whose top-level
erroris a non-empty string/object, which isn't a validsuccess shape for any DCI endpoint.
Test plan
go build ./... && go vet ./... && go test ./...extraction/priority,
jsonApplicationErrorcases, and guard behavior(HTML swallowed + flagged; 2xx-error body printed + flagged; JSON/SSE
delegate untouched).
non-zero exit; confirm a normal query and
ask-ava-streamingare unaffected.