Skip to content

refactor(cli): name every exit-code site via exitcodes.go + cross-command docs table - #315

Merged
saadqbal merged 2 commits into
developfrom
refactor/284-exitcodes-naming
Jul 14, 2026
Merged

refactor(cli): name every exit-code site via exitcodes.go + cross-command docs table#315
saadqbal merged 2 commits into
developfrom
refactor/284-exitcodes-naming

Conversation

@LukasWodka

@LukasWodkaLukasWodka commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Summary

internal/cli/exitcodes.go names every exit code the CLI produces, and every non-test &exitError{code: N} site now uses a named constant. exit.go keeps owning the extraction — this is a naming sweep, not a redesign: every numeric value is unchanged and documented as frozen (they're the scripting contract customers branch on).

Site census — the ticket's grep count of 138 includes one doc comment in exit.go; 137 are real construction sites, now all named:

shapecount
code: 1exitFailure61
code: 2exitBadInput / exitChecksFailed (doctor)25
code: 3exitLocalEnv23
code: 4exitNoWorkspace7
code: 5exitAuth / exitNoSuchDataset (data delete)4
code: 6exitTableExists1
code: 7exitStagingFailed / exitTeardownFailed / exitQueryFailed5
code: 8exitSubmitFailed2
code: 9exitIngestFailed4
code: 130exitInterrupted2
kubeconfigExitCode(...) (helper now returns named constants)2
variable (runLocalPreflight's BadFlag fold, now built from constants)1

Codes that grew more than one per-command meaning get one constant per meaning sharing the value, so each construction site reads honestly (e.g. data delete's exit 5 is "no such dataset", not "auth").

docs/troubleshooting.md gains the cross-command exit-code table (code / meaning / producing commands / constant name), sourced from the per-command long-help blocks — data ingest's (now data_ingest_cmd.go; pre-split data.go:236-252) is the fullest.

Deviations from the ticket, verified against the code: real distribution is 61×1 / 25×2 / 23×3 / 7×4 (ticket said 63/27/24/9); there is nocode: 0 site (ticket said 1×0); the ticket missed the 2×130 Ctrl-C sites and the 2 kubeconfigExitCode sites.

Fixes#284
Part of tracebloc/backend#1106.

Type of change

  • Bug fix
  • New feature
  • Refactor (no functional change)
  • Docs
  • CI/build

Test plan

Ran locally:

  • go test ./... — full suite green
  • go build ./..., go vet, gofmt -s -l — clean
  • Post-sweep grep: zero numeric code: literals remain at non-test sites

Checklist

  • Tests pass locally
  • gofmt/vet clean
  • No behavior change; all numeric values identical

Stacked PR 3/4 of the WS-B data.go chain — merge order: cli#303 (#282) → cli#309 (#283) → this → cli#285. Branch is based on refactor/283-rundataingest-extract; until #303/#309 merge, this diff shows their commits too. Review only the top commit (a6de340).

🤖 Generated with Claude Code


Note

Low Risk
Refactor and docs only—exit numeric values are unchanged; the new file-budget gate only fails when tracked files exceed checked-in ceilings.

Overview
Introduces internal/cli/exitcodes.go with named constants for every CLI exit code (values unchanged and documented as frozen). All non-test &exitError{code: …} sites and helpers like ExitCodeFromError / kubeconfigExitCode now use those names instead of raw integers, including shared numbers that mean different things per command (exitAuth vs exitNoSuchDataset, the exit-7 trio, etc.).

docs/troubleshooting.md gains a cross-command exit-code table tied to the constant names for grepping.

Separately, scripts/file-budget.sh ratchets line counts on a few large files; make ci and the build.yml lint job run it so local and CI stay aligned.

Reviewed by Cursor Bugbot for commit ab1a923. Bugbot is set up for automated code reviews on this repo. Configure here.

@LukasWodka
LukasWodka requested a review from saadqbalJuly 14, 2026 12:35
@LukasWodka

Copy link
Copy Markdown
ContributorAuthor

👋 Heads-up — Code review queue is at 56 / 30

Above the WIP limit. The team convention is to review existing PRs before opening new work.

Open PRs currently in Code review (oldest first):

  • averaging-service#181 — feat(weights): normalize-on-read — mixed cycles average instead of rejecting (SEC-03 §8 step 2) · author: @shujaatTracebloc · no reviewer assigned
  • averaging-service#182 — feat(weights): averaging writes SafeTensors (TF + PyTorch) — SEC-03 §8 step 4 · author: @shujaatTracebloc · no reviewer assigned
  • backend#1079 — feat(global_meta): edge dataset_meta exposure + attributes contract at ingest (#924 G4a) · author: @divyasinghds · no reviewer assigned
  • backend#1086 — docs(rfc): SafeTensors weight-format migration — SEC-03 Phase 1 (RFC 0004) · author: @shujaatTracebloc · no reviewer assigned
  • backend#1093 — chore(deps): bump django from 5.2.14 to 5.2.15 · author: @dependabot · no reviewer assigned
  • backend#1095 — feat(experiment): configurable preprocessing knobs incl. tabular scaler — RFC 0003 L1 + L1b (#1094) · author: @LukasWodka · no reviewer assigned
  • backend#1100 — fix(boot): pin SDK install to tracebloc==0.11.2, drop 404 dev line (#1098) · author: @LukasWodka · reviewer: @saqlainsyed007
  • backend#1105 — perf(api): query micro-fixes — notifications N+1, cached data_scientist, composite index, sampling (#975) · author: @aptracebloc · no reviewer assigned
  • backend#1107 — perf(experiments): prefetch ExperimentListSerializer relations + cache carbon intensity (#977) · author: @aptracebloc · reviewer: @saadqbal
  • backend#1108 — test(api): CLI response-shape contract fixtures for the 9 CLI endpoints (WS-D.2) · author: @LukasWodka · reviewer: @saadqbal

Pull from review before opening new work. (This is a nudge from the kanban WIP check, not a block.)

@LukasWodka
LukasWodka changed the base branch from develop to refactor/283-rundataingest-extractJuly 14, 2026 12:49
@LukasWodkaLukasWodka self-assigned this Jul 14, 2026
@LukasWodka

Copy link
Copy Markdown
ContributorAuthor

@BugBot run

@cursorcursorBot 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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit a6de340. Configure here.

saadqbal
saadqbal previously approved these changes Jul 14, 2026

@saadqbalsaadqbal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍 Faithful mechanical refactor — the exitcodes.go constants match every code I'd verified across the commands (delete 4/5/7, submit 8/9, doctor 2, kubeconfig 3), the intentional shared numbers (2/5/7) are named per-context for readability, and the exit-code test matrix is green so nothing shifted. Naming these makes the exit contract much easier to audit. (Stacked on #309.)

@saadqbal

Copy link
Copy Markdown
Collaborator

Status: approved, stacked on #309 (refactor/283…) which got auto-closed during the merge batch (see #309). Once #309's branch is rebased onto develop + recovered as a fresh PR, re-root this on develop. No content issue.

@saadqbal
saadqbalforce-pushed the refactor/283-rundataingest-extract branch from a2464db to e04bc04CompareJuly 14, 2026 14:43
@saadqbal
saadqbalforce-pushed the refactor/284-exitcodes-naming branch from a6de340 to 8d93e43CompareJuly 14, 2026 14:43
Base automatically changed from refactor/283-rundataingest-extract to developJuly 14, 2026 15:52
@saadqbal
saadqbal dismissed their stale reviewJuly 14, 2026 15:52

The base branch was changed.

internal/cli/exitcodes.go names every exit code the CLI produces; every
non-test &exitError construction site now uses a named constant instead
of a bare number. exit.go keeps owning the extraction — this is a naming
sweep, not a redesign; all numeric values are unchanged (and documented
as frozen: they're the scripting contract customers branch on).
Site census (the ticket's count of 138 grep hits includes one doc
comment in exit.go; 137 are real construction sites):
61x1, 25x2, 23x3, 7x4, 4x5, 1x6, 5x7, 2x8, 4x9, 2x130,
2x kubeconfigExitCode(...) (the helper now returns named constants),
1x variable (runLocalPreflight's BadFlag fold, now built from
constants). Zero numeric literals remain at non-test sites.
Codes that grew more than one per-command meaning get one constant per
MEANING sharing the value (2: exitBadInput / doctor's exitChecksFailed;
5: exitAuth / data delete's exitNoSuchDataset; 7: exitStagingFailed /
exitTeardownFailed / exitQueryFailed), so each site reads honestly.
docs/troubleshooting.md gains the cross-command exit-code table (code,
meaning, producing commands, constant name), sourced from the per-command
long-help blocks — data ingest's (data_ingest_cmd.go, pre-split
data.go:236-252) is the fullest.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@saadqbal
saadqbalforce-pushed the refactor/284-exitcodes-naming branch from 8d93e43 to f12fa87CompareJuly 14, 2026 15:55

@saadqbalsaadqbal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-approving after rebase onto develop — the #309 commit it was stacked on is now in develop (#321), so the rebased diff is exactly #315's exit-code-naming change (+257/−141, exitcodes.go +89), same content I approved originally. Approval was auto-dismissed on the retarget.

saadqbal
saadqbal previously approved these changes Jul 14, 2026
…o make ci + build.yml (#316)
* refactor(cli): extract resolveLocalInput + connectIngestTarget from runDataIngest
runDataIngest was 586 lines; every pre-cluster step and the cluster
pre-flight now live in two named stanza functions, moved verbatim:
- resolveLocalInput (data_ingest_local.go) — steps 0–4 + the P3 content
preflight: flag guard, banner, guided prompts, ~-expansion +
existence-first check, table-name/category/misapplied-flag validation,
layout walk, per-category spec resolution, spec synthesis + schema
validation, local summary. Mutates a in place (via *runDataIngestArgs)
so the --output-json defer and the cluster steps see the resolved spec
exactly as before.
- connectIngestTarget (data_ingest_cluster.go) — steps 5–8a: kubeconfig
resolve, release + PVC discovery, verbose cluster summary, and the
destination-table guard (incl. the folded interactive replace decision,
which still flips a.Overwrite).
The jsonEmitted/named-return defer dance stays INSIDE runDataIngest,
next to the err it reads — both extracted functions feed that named
return, so the error-JSON contract is unchanged. The dry-run stop (which
sets jsonEmitted) also stays inside.
Only in-stanza edits are what the new signatures force: multi-value
returns on error paths, := to = where a named result already exists, and
&a -> a where a is already a pointer. Step order, output order, and exit
codes are untouched.
data.go: 693 -> 240 lines; runDataIngest: 586 -> 138.
Safety net: the #187 outcome-matrix table test + #264 mutation pins pass
untouched; full suite green under -race; coverage floors hold (82.7%).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* refactor(cli): name every exit-code site + cross-command docs table
internal/cli/exitcodes.go names every exit code the CLI produces; every
non-test &exitError construction site now uses a named constant instead
of a bare number. exit.go keeps owning the extraction — this is a naming
sweep, not a redesign; all numeric values are unchanged (and documented
as frozen: they're the scripting contract customers branch on).
Site census (the ticket's count of 138 grep hits includes one doc
comment in exit.go; 137 are real construction sites):
61x1, 25x2, 23x3, 7x4, 4x5, 1x6, 5x7, 2x8, 4x9, 2x130,
2x kubeconfigExitCode(...) (the helper now returns named constants),
1x variable (runLocalPreflight's BadFlag fold, now built from
constants). Zero numeric literals remain at non-test sites.
Codes that grew more than one per-command meaning get one constant per
MEANING sharing the value (2: exitBadInput / doctor's exitChecksFailed;
5: exitAuth / data delete's exitNoSuchDataset; 7: exitStagingFailed /
exitTeardownFailed / exitQueryFailed), so each site reads honestly.
docs/troubleshooting.md gains the cross-command exit-code table (code,
meaning, producing commands, constant name), sourced from the per-command
long-help blocks — data ingest's (data_ingest_cmd.go, pre-split
data.go:236-252) is the fullest.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* ci: file-budget line-count ratchet (scripts/file-budget.sh)
Clones the coverage-floor.sh pattern for file size: path:max_lines pairs,
checked by wc -l, portable to bash 3.2, with the same malformed-entry
guard — plus a missing-file guard so a moved/renamed budgeted file makes
the stale list loud instead of silently un-budgeting it.
Ceilings are a RATCHET: only ever lowered as files shrink; raising one is
a deliberate, reviewed edit to the checked-in script. Seeds sit just
above today's reality (develop + the WS-B split):
internal/push/preflight.go:1650 (now 1635)
internal/cli/data.go:500 (now 240 post cli#282/#283)
internal/cli/client.go:1050 (now 1027)
internal/cli/home.go:850 (now 841)
Wired into `make ci` (new file-budget target, keeping the Makefile's
"make ci green => CI green" invariant) and into build.yml's lint job as
one surgical step. Exercised all three failure paths locally (over
budget, missing file, malformed entry) — each exits 1 with a ::error::
annotation; shellcheck clean.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* ci(file-budget): seed preflight.go at true size (Bugbot #316 HIGH)
The ratchet seeded internal/push/preflight.go at 1650, but the file is
1655 lines (wc -l, same count the gate uses) and the check is strict-
greater — so `make file-budget` would fail the moment this landed on
develop. Raise the ceiling to 1700, the next round-50 ratchet value just
above actual, matching how the other seeds sit above their files
(client.go 1050>1027, home.go 850>849, data.go 500>240). Also correct
the header comment to reality (preflight ~1655, home ~849); it wrongly
read ~1635 / ~841.
Proof: `bash scripts/file-budget.sh` now passes (preflight 1655 <= 1700).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>

@saadqbalsaadqbal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-approving — #316 merged into this PR's base branch, so #315 now carries both the exit-code-naming change AND #316's file-budget ratchet (both previously approved; build.yml keeps govulncheck + adds the File-budget step). Merging this lands both on develop. Approval was auto-dismissed when #316's commit was added.

@saadqbal
saadqbal merged commit 6574801 into developJul 14, 2026
19 checks passed
@saadqbal
saadqbal deleted the refactor/284-exitcodes-naming branch July 14, 2026 16:04
Sign up for freeto 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

@LukasWodka@saadqbal