Add did-you-mean hint when --token/--key credentials are swapped#916
Draft
epompeii wants to merge 1 commit into
Draft
Add did-you-mean hint when --token/--key credentials are swapped#916epompeii wants to merge 1 commit into
epompeii wants to merge 1 commit into
Conversation
Passing a Bencher API key to `--token` or a JWT to `--key` previously failed with an opaque validation error. Add clap value parsers for both fields that detect the swap (the two credential types are structurally disjoint) and redirect the user to the correct flag.
Contributor
🤖 Claude Code ReviewPR: #916 Code Review:
|
Contributor
|
| Branch | claude/cli-token-key-help-po6i5z |
| Testbed | intel-v1 |
Click to view all benchmark results
| Benchmark | Latency | Benchmark Result microseconds (µs) (Result Δ%) | Upper Boundary microseconds (µs) (Limit %) |
|---|---|---|---|
| Adapter::Json | 📈 view plot 🚷 view threshold | 4.58 µs(-0.70%)Baseline: 4.62 µs | 4.86 µs (94.25%) |
| Adapter::Magic (JSON) | 📈 view plot 🚷 view threshold | 4.46 µs(-0.69%)Baseline: 4.49 µs | 4.70 µs (94.87%) |
| Adapter::Magic (Rust) | 📈 view plot 🚷 view threshold | 26.08 µs(+2.19%)Baseline: 25.52 µs | 26.54 µs (98.25%) |
| Adapter::Rust | 📈 view plot 🚷 view threshold | 3.54 µs(+1.58%)Baseline: 3.48 µs | 3.59 µs (98.48%) |
| Adapter::RustBench | 📈 view plot 🚷 view threshold | 3.52 µs(+1.04%)Baseline: 3.48 µs | 3.58 µs (98.11%) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Bencher recently moved from recommending
--token(a JWT) to--key(abencher_user_*/bencher_run_*API key) for CLI authentication. Users and agents still reach for the old--tokenflag and sometimes pass the wrong credential type into the wrong flag. Previously this produced an opaque validation error:--tokenfailed withFailed to validate JWT (JSON Web Token): ...--keyfailed withFailed to validate Bencher API key: ...Neither message told the user they simply used the wrong flag.
Change
Add clap
value_parserfunctions for thetokenandkeyfields ofCliBackendthat wrap the existingFromStrparsing and, on failure, detect whether the supplied value is actually the other credential type and emit a redirecting hint:Detection reuses the existing
FromStrimpls (no new prefix/format logic): JWTs and API keys are structurally disjoint, so a value that fails one parser and succeeds the other is unambiguously a swap. Genuinely malformed values fall through to the original validation error (no false hint). Because clap runs value parsers on env-var values too, the hint also fires forBENCHER_API_TOKEN/BENCHER_API_KEY.This mirrors the existing
check_env/check_volumevalue-parser pattern already used in the CLI parser.Tests
Added 8 unit tests covering both swap directions, both key types (
bencher_user_*andbencher_run_*), valid inputs, and the garbage-without-hint fall-through.Verification
cargo test -p bencher_cli(8 new tests pass)cargo clippy -p bencher_cli --all-targets --all-features --no-deps -- -Dwarningscleancargo fmt--tokenhint, JWT to--keyhint, garbage to plain error)