Skip to content

feat(cli): name the next command in scope, credential, and login errors - #24

Open
thebrandonlucas wants to merge 1 commit into
feat/cli-interactive-pickersfrom
feat/cli-error-hints
Open

thebrandonlucas wants to merge 1 commit into
feat/cli-interactive-pickersfrom
feat/cli-error-hints

Conversation

@thebrandonlucas

Copy link
Copy Markdown
Contributor

Stack: master ← #20 ← #22 ← this PR ← #19. Depends on #22 (pickers), which handles a missing scope interactively; this PR improves the errors that noninteractive runs still see.

Errors now name the next command, not only the problem:

Error Hint
Missing --org, --env, --wallet, or webhook ID The command that lists the IDs, and each way to supply one (flag, VOLTAGE_* variable, profile)
Unknown or ambiguous credential, key bound to another scope The saved credential names
Unknown profile The saved profile names, or how to create one
Expired or revoked login (OAuth invalid_grant) voltage login --account NAME
organizations list / environments list with an API key Which key was used, and how to select a browser login
HTTP 401 voltage auth status, or sign in again
HTTP 403 voltage context, to check the organization, environment, and credential

Credential hints are attached in CredentialProblem::error, so voltage context and commands share one selection path. Hints can now be built at runtime and are scrubbed like messages, because they can name saved credentials and profiles. docs/reference/exit-codes.md lists them.

The --yes refusal hint from the original plan is dropped: #14 replaced confirmation prompts with --execute, and the not-executed error already names --execute and VOLTAGE_EXECUTE=1.

Validation: cargo fmt --check, cargo clippy --locked --all-targets -- -D warnings, cargo machete --with-metadata, cargo test --locked (93 unit, 67 integration), and python3 scripts/check-coverage.py. New integration tests cover the 401/403 hints, a revoked login, saved credential and profile names, and discovery with an ambient API key.

Errors for a missing --org, --env, --wallet, or webhook ID now name the
command that lists those IDs and every way to supply one. An unknown or
ambiguous credential or profile lists the saved names. An expired or revoked
login (OAuth invalid_grant) says so and gives the exact voltage logout
--local and voltage login commands that replace it. organizations list and environments list with an API key say which
key was used and how to select a browser login.

API rejections carry a next step: HTTP 401 points to voltage auth status,
HTTP 403 points to voltage context, and quote_required points to voltage
quotes create and notes that a wallet on a BTC line of credit needs no
quote. Hints can now be built at runtime and are scrubbed like
messages, since they can name saved credentials.

A rejection's message leads with the API's own reason, such as "Quote is
required for payment", instead of only the HTTP status. Human output shows
the rest of the API error as indented field/value lines rather than a JSON
line; --json still reports the complete response. The payments guide shows
the quote-then-receive flow a USD wallet needs.
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