fix(api): distinguished a token-fetch failure from an unconfigured party - #360
Merged
Merged
Conversation
get_party_credentials returned Option<(String, CantonId)>, collapsing "no auth configured", "party unknown", and "token fetch failed" into one None with the underlying error silently discarded. Changed the return type to Result<Option<(String, CantonId)>>: Ok(None) still covers the first two (both are ordinary, non-error outcomes), while Err now carries the token fetch failure and is logged with the party id before being returned. Updated all seven governance.rs call sites plus the reward automation call site to match: the six action handlers and the coupon-reassignment-delegation read now answer a token fetch failure with 500 instead of folding it into the existing 401, while the reward automation loop keeps its no-op behavior for both non-credential outcomes since it already handles this failure mode separately.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refines the server-side auth credential lookup flow by distinguishing “no credentials available” from “token fetch failed,” allowing callers (notably governance endpoints) to respond with an actual server error instead of silently treating token acquisition failures as missing configuration.
Changes:
- Changed
get_party_credentialsto returnResult<Option<(String, CantonId)>>, returningErron token-fetch failures and logging a warning with the party id. - Updated all governance handler call sites to treat
Ok(None)as401 Unauthorized(unchanged behavior) andErr(_)as500 Internal Server Error. - Added unit/integration-style tests in
governance.rsto cover: no auth configured, unknown party, and token fetch failure (including asserting the warning log contains the party id).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/decman/src/server/reward_automation.rs | Adapts reward automation to the new get_party_credentials signature while preserving prior no-op behavior on missing/failed credentials. |
| crates/decman/src/server/handlers/governance.rs | Implements the new Result<Option<_>> credential API, updates governance endpoints’ error handling, and adds tests for the three credential outcomes. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
scolear
approved these changes
Aug 19, 2026
schronck
added a commit
that referenced
this pull request
Aug 24, 2026
#353, #355, #360 and #361 landed since the last sync. The only conflict was fetch_governance_with_wildcard: this branch still carried it, adapted to DomainConfirmation, while #355 deleted every test-mode wildcard path on main. Took the deletion. Verified after: clippy clean, gen-types 0 warnings, 477 tests pass, and the placeholder action is still absent.
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.
What
get_party_credentialscollapsed three outcomes into a singleOption::None:data.authisNone)registry.get(party_id))tm.get_token().await) — an actual error, previously discarded via.ok()?with no loggingChanged the return type to
Result<Option<(String, CantonId)>>:Ok(None)): unchanged behavior everywhere — both are ordinary "this party has no usable credentials" outcomes callers never needed to tell apart.Err): now logged withtracing::warn!(%party_id, error = %e, ...)at the point the error is available, and returned instead of silently discarded.Call sites
Updated all 7 call sites in
handlers/governance.rs(propose_action,confirm_action,execute_action,expire_confirmation,cancel_confirmation,cancel_proposal,get_coupon_reassignment_delegation) to answer a token-fetch failure with500 Internal Server Error(a new, distinct response from the existing401 Unauthorizedused for "no credentials configured"), matching the precedent already used for the same failure inhandlers/auth.rs.The reward automation call site (
reward_automation.rs::run_once_for_party) keeps its exact prior behavior — bothOk(None)andErrstill fold into a no-opOk(())— since #325 already gives that path its own handling for this failure mode; this PR only keeps the call site compiling against the new signature. The warning is still logged from insideget_party_credentialsregardless.Tests
Added
get_party_credentials_testsingovernance.rscovering all three outcomes against a realAppState:Ok(None)Ok(None)wiremockKeycloak stand-in) →Err, with the warning log asserted to contain the party idVerification
cargo fmt --check— cleanDECMAN_SKIP_FRONTEND=1 cargo clippy --all-targets --all-features --no-deps -- -D warnings— cleanDECMAN_SKIP_FRONTEND=1 cargo test -p decman --lib— 424 passedCloses #326