Skip to content

Add a global JSON error envelope with stable codes and next_steps#1282

Merged
no-itsbackpack merged 10 commits into
mainfrom
cli/workflow-json-next-steps
Jul 8, 2026
Merged

Add a global JSON error envelope with stable codes and next_steps#1282
no-itsbackpack merged 10 commits into
mainfrom
cli/workflow-json-next-steps

Conversation

@no-itsbackpack

@no-itsbackpack no-itsbackpack commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Unhandled command errors in --format json mode now print a single structured envelope on stdout: status, error, issues: [{code, message}], next_steps, matching the schema used by auth check, sql, and import d1
  • Errors are classified into stable codes (NO_AUTH, NOT_FOUND, CONFIRMATION_REQUIRED, NETWORK_ERROR, INVALID_USAGE, ...) with remediation commands in next_steps
  • ANSI color sequences are stripped from messages before they reach JSON payloads
  • The error envelope and code vocabulary are documented in the embedded AGENTS.md agent guide
  • Workflow-specific JSON handling was reverted out of this PR to keep it focused on the global handler; it can follow separately

Test plan

  • go test ./internal/...
  • Manual smoke test: pscale database list --org <bogus> --format json returns the NOT_FOUND envelope with discovery next_steps

… error envelope.

Workflow commands (create, cutover, cancel, switch-traffic, etc.) now return
status/issues/next_steps JSON with contextual remediation commands in --format
json mode. Unhandled errors on any command now fall back to a classified
{status, code, error, next_steps} envelope on stdout instead of a bare
{"error"} blob on stderr.

Co-authored-by: Cursor <cursoragent@cursor.com>
@no-itsbackpack no-itsbackpack requested a review from a team as a code owner July 7, 2026 20:19
Comment thread internal/cmd/workflow/json.go Outdated
…ommands.

Auth failures (expired token, not authenticated) surfaced through workflow
subcommands now report NO_AUTH with login next_steps instead of a generic
WORKFLOW_ERROR, matching the remediation agents get on any other command.

Co-authored-by: Cursor <cursoragent@cursor.com>
Comment thread internal/cmdutil/json_error.go
A bare "timeout" substring match swallowed operation and deadline
timeouts (e.g. workflow cutover timeouts), giving agents connectivity
remediation instead of command-specific next_steps. Match specific
transport error strings (i/o timeout, TLS handshake timeout, connection
refused/reset, no such host) instead.

Co-authored-by: Cursor <cursoragent@cursor.com>
Comment thread internal/cmd/workflow/cutover.go Outdated
…mmands

The JSON confirmation envelope replaced the old Format() != Human guard,
which let --format csv fall through to interactive confirmation on a TTY
for cancel, cutover, and switch-traffic. Reinstate the format error after
the JSON branch so non-JSON machine formats fail fast without --force.

Co-authored-by: Cursor <cursoragent@cursor.com>
@no-itsbackpack no-itsbackpack changed the title Add structured JSON next_steps to workflow commands and a global JSON error envelope Add a global JSON error envelope with stable codes and next_steps Jul 8, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b7ce77a. Configure here.

Comment thread internal/cmdutil/json_error.go Outdated
no-itsbackpack and others added 3 commits July 8, 2026 15:05
@cursor

cursor Bot commented Jul 8, 2026

Copy link
Copy Markdown

Current version of PR was reviewed by /review-bugbot on Jul 8, 20:20. It flagged 2 findings.

Show 2 findings

1. SQL errors always COMMAND_FAILED

internal/cmd/sql/json.go:42 · High Severity

The SQL JSON error path now always sets issues[].code to COMMAND_FAILED for every non-destructive failure, even when the underlying error is clearly auth, not-found, or network-related. That contradicts AGENTS.md, which tells agents to branch on stable issues[].code values such as NO_AUTH and NOT_FOUND.

2. AUTH_INVALID never emitted globally

internal/cmdutil/json_error.go:48 · Medium Severity

AGENTS.md documents AUTH_INVALID as a stable issues[].code for stored credentials rejected by the API, but GlobalJSONError never assigns that code. Rejected-credential failures that do not match the narrower NO_AUTH, SERVICE_TOKEN_INVALID, or other patterns fall through to COMMAND_FAILED.

Bugbot on commit 838f2a7 is skipped.

@no-itsbackpack no-itsbackpack merged commit b0914f1 into main Jul 8, 2026
4 checks passed
@no-itsbackpack no-itsbackpack deleted the cli/workflow-json-next-steps branch July 8, 2026 20:35
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.

2 participants