Skip to content

[VPEX][12] Report incompatible target flags as E_USAGE#5963

Open
rugpanov wants to merge 2 commits into
dbconnect/12-serverless-v5from
dbconnect/13-usage-error
Open

[VPEX][12] Report incompatible target flags as E_USAGE#5963
rugpanov wants to merge 2 commits into
dbconnect/12-serverless-v5from
dbconnect/13-usage-error

Conversation

@rugpanov

Copy link
Copy Markdown
Contributor

Stacked on #5962 (serverless-v5) → #5961#5960#5959.

What

Per the [P0] CLI Changes spec, a bad-flags usage error is now surfaced as E_USAGE at the preflight phase, through the phase/JSON contract — instead of a bare Cobra mutual-exclusion error printed before RunE (which produces no command JSON object).

Why

The VS Code extension branches on the JSON error.code. Previously, passing two target flags triggered Cobra's MarkFlagsMutuallyExclusive before RunE, so --output json emitted nothing structured. Now the conflict is caught inside the pipeline and reported like any other phase failure.

Changes

  • Add the E_USAGE error code.
  • Validate target flags at the top of the pipeline's preflight → E_USAGE, diskMutated=false.
  • Drop cmd.MarkFlagsMutuallyExclusive and the redundant early-return in runPipeline so the conflict flows into the pipeline.
  • flag-conflict golden updated (now shows the phase table + preflight error); new flag-conflict-json asserts error{code:"E_USAGE", failurePhase:"preflight"}; pipeline unit test for the path.

Testing

go build ./..., lint (0 issues), deadcode clean, unit + acceptance green.

This pull request and its description were written by Isaac.

@github-actions

Copy link
Copy Markdown
Contributor

Waiting for approval

Could not determine reviewers from git history.
Round-robin suggestion: @lennartkats-db

Eligible reviewers: @andrewnester, @anton-107, @denik, @janniklasrose, @lennartkats-db, @pietern, @renaudhartert-db, @shreyas-goenka, @simonfaltum

Suggestions based on git history. See OWNERS for ownership rules.

@rugpanov rugpanov changed the title [VPEX] Report incompatible target flags as E_USAGE [VPEX][12] Report incompatible target flags as E_USAGE Jul 17, 2026
@eng-dev-ecosystem-bot

eng-dev-ecosystem-bot commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

Integration test report

Commit: 27b9d27

Run: 29585176700

Env 💚​RECOVERED 🙈​SKIP ✅​pass 🙈​skip Time
💚​ aws linux 4 4 227 1123 4:49
💚​ aws windows 4 4 229 1121 9:05
💚​ aws-ucws linux 4 4 316 1039 6:20
💚​ aws-ucws windows 4 4 318 1037 7:28
💚​ azure linux 4 4 227 1122 4:55
💚​ azure windows 4 4 229 1120 6:58
💚​ azure-ucws linux 4 4 318 1036 6:55
💚​ azure-ucws windows 4 4 320 1034 10:08
💚​ gcp linux 4 4 226 1124 4:55
💚​ gcp windows 4 4 228 1122 9:00
8 interesting tests: 4 RECOVERED, 4 SKIP
Test Name aws linux aws windows aws-ucws linux aws-ucws windows azure linux azure windows azure-ucws linux azure-ucws windows gcp linux gcp windows
💚​ TestAccept 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
🙈​ TestAccept/bundle/invariant/no_drift 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/vector_search_endpoints/drift/recreated_same_name 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/vector_search_indexes/recreate/embedding_dimension 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/ssh/connection 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
💚​ TestFetchRepositoryInfoAPI_FromRepo 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
💚​ TestFetchRepositoryInfoAPI_FromRepo/root 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
💚​ TestFetchRepositoryInfoAPI_FromRepo/subdir 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
Top 10 slowest tests (at least 2 minutes):
duration env testname
8:49 azure-ucws windows TestAccept
8:35 aws windows TestAccept
8:32 gcp windows TestAccept
6:30 azure windows TestAccept
6:22 aws-ucws windows TestAccept
2:59 aws linux TestAccept
2:58 gcp linux TestAccept
2:58 azure linux TestAccept
2:51 aws-ucws linux TestAccept
2:49 azure-ucws linux TestAccept

Per the [P0] CLI Changes spec, a bad-flags usage error is now surfaced as
E_USAGE at the preflight phase, through the phase/JSON contract, instead
of a bare Cobra mutual-exclusion error printed before RunE.

- Add the E_USAGE error code.
- Validate target flags at the top of the pipeline's preflight; a conflict
  fails preflight with E_USAGE (diskMutated=false).
- Drop cmd.MarkFlagsMutuallyExclusive and the redundant early return in
  runPipeline so the conflict flows into the pipeline and --output json
  emits the structured error{code:"E_USAGE", failurePhase:"preflight"}
  object the VS Code extension branches on.
- flag-conflict golden updated; new flag-conflict-json asserts the JSON
  error object; pipeline unit test for the E_USAGE path.

Co-authored-by: Isaac
@rugpanov
rugpanov force-pushed the dbconnect/12-serverless-v5 branch from 179ea18 to 846170a Compare July 17, 2026 13:27
@rugpanov
rugpanov force-pushed the dbconnect/13-usage-error branch from f20628a to 6b4a2a4 Compare July 17, 2026 13:27
…ssage

codex P2 on #5963: with --output json, error.message came from
PipelineError.Msg only ('invalid compute target flags'), while the
wrapped validation error is json:"-" — so JSON consumers lost which
flags conflicted. Fold the validation detail into Msg (and do not wrap
err, since PipelineError.Error() appends a non-nil Err and would
duplicate the detail in text output; E_USAGE is the stable contract, not
the raw error). Both text and JSON now carry the full actionable message.

Co-authored-by: Isaac

@anton-107 anton-107 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed as part of the full stack (#5960#5965). The intent here is right — routing the mutual-exclusion conflict through the phase/JSON contract so --output json emits a structured error instead of a bare pre-RunE Cobra error. Removing the runPipeline early return is safe: ValidateTargetFlags still runs at pipeline preflight (pipeline.go:100), with ResolveTarget (target.go:73) as a defensive second check, so no call path goes unvalidated. Leaving this as a comment (not a block), but two gaps undercut the stated rationale and are worth addressing before this is relied on:

  • [high] The JSON error object drops the actionable detail. PipelineError.Err is json:"-" (libs/localenv/result.go:98), so the emitted object is just {"code":"E_USAGE","failurePhase":"preflight","message":"invalid compute target flags"} — it never says which flags conflict. The text path shows the full …: flags --cluster-id and --serverless-version are mutually exclusive; specify at most one (compare goldens flag-conflict/output.txt vs flag-conflict-json/output.txt). So the --output json consumer this PR is written to serve gets strictly less information than the terminal user. This is not E_USAGE-specific: the same loss makes E_RESOLVE's ambiguous-vs-unknown cluster-name cases marshal to byte-identical JSON, and drops the job-ambiguity detail too. If the JSON contract matters, folding the cause into Msg (or serializing Error()) is the fix.

  • [medium] E_USAGE is unreachable in JSON mode when auth isn't set up. setup_local.go:40 sets PreRunE = root.MustWorkspaceClient, which Cobra runs before RunE (and thus before the preflight where E_USAGE is emitted). A flag conflict needs zero workspace access, yet with no/invalid auth the user gets a plain non-JSON auth error, never the promised {"code":"E_USAGE"} object — precisely in the "haven't logged in yet" case.

  • [low] JSON contract untested for the lossy codes. The only --output json goldens cover E_USAGE and E_NO_TARGET — the two codes whose whole message lives in Msg (nothing to lose). No JSON golden exercises E_RESOLVE / E_FETCH / E_ENV_UNSUPPORTED, which are exactly the paths where the message-loss above bites, so a regression there would pass CI.

  • [low] Shell completion no longer signals mutual exclusivity. Dropping MarkFlagsMutuallyExclusive means completion no longer hides the sibling target flags after one is set (verified against a built binary). Acceptable given the command is hidden/experimental — flagging for awareness, not as a blocker.

Reviewed with AI assistance (build + unit tests + adversarial verification against the checked-out top of stack).

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.

3 participants