Skip to content

fix(cli): make identity resolution and piped output diagnosable - #155

Merged
graywolf336 merged 4 commits into
devfrom
fix/cli-diagnostics
Aug 7, 2026
Merged

graywolf336 merged 4 commits into
devfrom
fix/cli-diagnostics

Conversation

@graywolf336

@graywolf336 graywolf336 commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Four defects found while debugging an opaque 401 Token references an identity that is not registered. Each one individually hid information the user had explicitly asked for, and together they turned a one-line misconfiguration into a long hunt.

The fixes

--verbose was a no-op — every command advertises -v, --verbose Emit extra diagnostic output, but the parsed field was never read. env_logger was initialised before clap ran, so only RUST_LOG could raise the level. The debug lines naming the authenticating identity already existed; they were simply unreachable through the documented flag. The filter is scoped to atomic, which prefix-matches both this binary's atomic::… module paths (the [[bin]] name, not the package name) and the atomic_* libraries, so reqwest/hyper wire logging doesn't bury the answer. RUST_LOG still wins when set.

Silent fallback to the default identity — when a server profile declares no identity, the client quietly uses the global default. If that isn't the identity registered with the server, the only symptom is a 401 from the far end naming no identity at all. Now logs which identity was chosen, says it was a fallback, and names the command that binds one.

Progress completions vanished off-TTY — indicatif hides its draw target when stderr isn't a terminal, which is right for the animation but also swallowed finish_with_message. A piped atomic view switch printed nothing: no confirmation, and no N conflicts detected warning either. Scripts, CI logs and agents saw an empty stream from a command that had done real work.

Latent panic in error reporting — the undeserializable-response path sliced &body[..200], which panics when the cut lands inside a multi-byte character. An accented name or smart quote in a server message was enough to abort the CLI mid-report. Now walks to a character boundary; preview raised to 2000 bytes (200 routinely cut off before the offending field) with the full body at debug level.

Before / after

Recreating the original broken state by removing an identity binding:

old:  ✗ HTTP error 401: Token references an identity that is not registered

new:  DEBUG Server profile https://staging.atomic.storage declares no identity;
        falling back to the default identity 'bradley'.
        Bind one with 'atomic server set-identity <profile> <identity>'.

Testing

cargo test --workspace — 0 failures. cargo fmt --check and cargo clippy --all-targets clean on every changed crate. Each of the four commits was checked out individually and verified to build (cargo check --workspace --all-targets) and test green, so the branch bisects cleanly and any commit can be reverted alone.

Behaviour verified against live staging and production, plus a real pty to confirm the progress fix doesn't double-print on a TTY.

Six new tests cover the truncation helper, including one walking every truncation offset through multi-byte characters.

Notes

  • A fifth fix for GrantSubjectType not accepting everyone was dropped from this branch — fix(teams): accept everyone workspace grants #151 already covers it, and does so more thoroughly (it also guards the mutation helpers against the response-only variant).

Not addressed (server-side)

  • atomic org list returns HTTP 405 — GET /orgs isn't routed on staging or production, though POST /orgs is.
  • org member list resolves the org before validating the token, so a bad slug masks auth state entirely.

@graywolf336
graywolf336 force-pushed the fix/cli-diagnostics branch from 36eb620 to b31e940 Compare August 6, 2026 23:48
@graywolf336
graywolf336 force-pushed the fix/cli-diagnostics branch from b31e940 to bb89c64 Compare August 7, 2026 14:58
Base automatically changed from bug/workspace-default to dev August 7, 2026 15:21
Every command advertises "-v, --verbose  Emit extra diagnostic output",
and the flag was parsed into a field nothing ever read. env_logger was
initialised before clap ran, so only RUST_LOG could raise the level and
the documented flag did nothing at all.

Scan argv for the flag before initialising, since logging has to be live
before parsing (parsing itself can fail, and that trail is worth having)
and a global flag's position is unconstrained.

Scope the filter to `atomic`, which prefix-matches both this binary's
`atomic::…` module paths — the [[bin]] name, not the atomic-cli package
name — and every `atomic_*` library crate. A bare `debug` would pull in
reqwest and hyper wire logging and bury the line the user came for.
RUST_LOG still wins when set.
When a server profile declares no identity the client silently falls
back to the global default. If that default is not the identity
registered with the server, the only symptom is a 401 from the far end
that names no identity at all — the local side of the mistake is
invisible, so diagnosis means guessing which of several local
identities was used.

Log the chosen identity in both branches, say explicitly when it was a
fallback rather than a binding, and name the command that fixes it.

Pairs with --verbose actually working; before that these lines were only
reachable through RUST_LOG.
indicatif defaults to a stderr draw target that suppresses itself off
TTY. That is right for the animation — a spinner in a log file is noise
— but finish_with_message goes through the same target, so the outcome
line disappeared with it.

A piped `atomic view switch` therefore printed nothing whatsoever: no
confirmation that the switch happened, and no "N conflicts detected"
warning either. Scripts, CI logs and agents saw an empty stream from a
command that had done real work.

Emit the message directly when the bar is hidden. Plain text, no ANSI,
since the consumer is a pipe. On a TTY the bar renders it as before and
the fallback stays quiet, so there is no double-print.
The undeserializable-response path quoted `&body[..200]`. Slicing a str
at an arbitrary byte offset panics when the index lands inside a
multi-byte character, so any error body carrying non-ASCII text — an
accented name, a smart quote in a server message — could abort the CLI
while it was in the middle of reporting a different failure.

Walk back to a character boundary instead.

Raise the preview to 2000 bytes while here: 200 routinely cut off before
the offending field, producing an error that named a problem the reader
could not see. The full body now goes to the debug log regardless, so
the bound is only about keeping the terminal readable.
@graywolf336
graywolf336 force-pushed the fix/cli-diagnostics branch from bb89c64 to 204c6c8 Compare August 7, 2026 15:21
@graywolf336
graywolf336 merged commit 428193d into dev Aug 7, 2026
8 checks passed
@graywolf336
graywolf336 deleted the fix/cli-diagnostics branch August 7, 2026 15:39
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.

2 participants