Skip to content

feat(errors): AuthmuxError taxonomy + --json on 5 core commands (N3)#28

Merged
NagyVikt merged 1 commit into
mainfrom
agent/n3-error-taxonomy
May 17, 2026
Merged

feat(errors): AuthmuxError taxonomy + --json on 5 core commands (N3)#28
NagyVikt merged 1 commit into
mainfrom
agent/n3-error-taxonomy

Conversation

@NagyVikt
Copy link
Copy Markdown
Collaborator

Summary

Theme N3 from docs/future/17-ROADMAP.mdError taxonomy + --json parity for the five core commands.

  • New AuthmuxError base class with stable code, severity, hint, details, toJSON() (per 01-ARCHITECTURE.md §6.2). Every class in src/lib/accounts/errors.ts (AuthFileMissingError, AccountNotFoundError, NoAccountsSavedError, InvalidAccountNameError, AccountNameInferenceError, SnapshotEmailMismatchError, PromptCancelledError, InvalidRemoveSelectionError, AmbiguousAccountQueryError, AutoSwitchConfigError) now extends it with a stable E_* code. CodexAuthError is kept as a back-compat subclass so existing instanceof CodexAuthError catches still work.
  • --json flag added to list, current, status, use, save. Output is a single JSON object on stdout; nothing else. Interactive prompts (update offer, account picker) are skipped under --json so stdout stays parseable.
  • Central error handler in BaseCommand now routes AuthmuxError to the envelope under --json and exits with the §6.3 exit code.
  • src/tests/error-taxonomy.test.ts enforces the §6.2 code allowlist, the severity table, CodexAuthError back-compat, the toJSON() shape, and the exit-code table.

Per N3 Risks: human-readable message strings are unchanged in this round. Scripts that grep stdout will keep working.

JSON envelope

// success
{ "ok": true, "data": { /* command-specific payload */ } }

// error
{ "ok": false, "error": { "code": "E_ACCOUNT_NOT_FOUND", "severity": "fatal",
                          "message": "...", "hint": "...",
                          "details": { "name": "alice" } } }

Exit codes follow §6.3: 3 E_AUTH_MISSING, 4 E_ACCOUNT_NOT_FOUND, 5 E_SNAPSHOT_EMAIL_MISMATCH, 6 E_REGISTRY_LOCKED, 7 E_REGISTRY_CORRUPT, 8 E_PROVIDER_NOT_INSTALLED, 64 E_PROMPT_CANCELLED, 1 generic.

Exit-criteria boxes (Theme N3)

  • AuthmuxError class lands with code, severity, hint, details, and toJSON().
  • Every class in src/lib/accounts/errors.ts extends AuthmuxError with a stable code per §6.2.
  • The five core commands (list, current, status, use, save) accept --json and write a single JSON object to stdout.
  • Exit codes follow the table in §6.3.
  • src/tests/error-taxonomy.test.ts enforces the code/severity table.

Test plan

  • npm run build — clean
  • npm test — 89/89 pass (4 new, 85 prior)
  • node dist/index.js list --json | JSON.parse(...) — single valid envelope
  • authmux use does-not-exist --json emits E_ACCOUNT_NOT_FOUND envelope and exits 4
  • authmux list --help shows the --json flag
  • CI matrix (Ubuntu/macOS/Windows × Node 18/20/22) — pending on PR

Coordination note

Sibling PRs from N1 (durability — touches account-service.ts, registry.ts) and N4 (paths deprecation — touches src/lib/config/paths.ts and several command callers) are running in parallel. Expect a rebase if they land first; the conflict surface is small (this PR only touches command files at the parse(...) boundary, not paths.ts or registry.ts).

🤖 Generated with Claude Code

Theme N3 from docs/future/17-ROADMAP.md.

- src/lib/accounts/errors.ts: introduce AuthmuxError base with stable
  ErrorCode/ErrorSeverity (per 01-ARCHITECTURE.md §6.2), hint, details,
  and toJSON(). Refactor every existing class (AuthFileMissingError,
  AccountNotFoundError, NoAccountsSavedError, InvalidAccountNameError,
  AccountNameInferenceError, SnapshotEmailMismatchError,
  PromptCancelledError, InvalidRemoveSelectionError,
  AmbiguousAccountQueryError, AutoSwitchConfigError) to extend it with
  the documented stable codes. CodexAuthError is preserved as a
  back-compat subclass of AuthmuxError.
- Human-readable `message` strings are unchanged in this round (per N3
  Risks: scripts grep against existing messages).
- src/lib/cli/json-envelope.ts: defines the single JSON envelope shape
  ({ ok: true, data } / { ok: false, error: errorObj.toJSON() }) and the
  §6.3 exit-code table mapper.
- src/lib/base-command.ts: adds BaseCommand.jsonFlag, setJsonMode(),
  emit() helper, and an AuthmuxError-aware central handler that routes
  to the JSON envelope when --json is set and exits with the §6.3 code.
- src/commands/{list,current,status,use,save}.ts: opt into
  BaseCommand.jsonFlag, route output through emit(), and suppress
  interactive prompts under --json so stdout stays parseable.
- src/tests/error-taxonomy.test.ts: enforces the §6.2 code allowlist,
  the §6.3 severity assignments, CodexAuthError back-compat, the
  toJSON() shape, and the exit-code table.

Verification: npm run build clean; npm test 89/89 pass;
`authmux list --json` round-trips through JSON.parse.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@NagyVikt NagyVikt merged commit 64349b3 into main May 17, 2026
12 checks passed
NagyVikt added a commit that referenced this pull request May 18, 2026
Bumps package.json + package-lock.json from 0.1.24 to 0.1.25 and
extends releases/v0.1.25.md to cover every theme that landed since
v0.1.24:

- N1 durability (#29): atomic writes, registry lock, fsync-before-rename
- N2 account-service split (#30): 1675 LOC -> 164 LOC orchestrator + 12 modules
- N3 error taxonomy + --json (#28): AuthmuxError base, stable codes, JSON envelope
- N4 lazy path resolvers (#27): bare constants deprecated for v0.2.0
- P0 wave (#26): secure perms, [y/N] update prompt, kiro ENOENT, CI matrix,
  registry proxy-source round-trip, 18k-line improvement docs

Notes follow the canonical 7-section shape from
docs/future/17-ROADMAP.md (Added, Changed, Fixed, Deprecated, Removed,
Security, Migration), with the prior Durability section folded into a
"Theme deep-dives" appendix so the canonical shape is intact.

No code changes. No npm publish.

Verification:
- npm run build: clean
- npm test: 129/129 pass
- node -e "require('./package.json').version" -> 0.1.25
- node -e "require('./package-lock.json').version" -> 0.1.25

Co-authored-by: NagyVikt <nagy.viktordp@gmail.com>
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.

1 participant