Skip to content

Commit

Permalink
fixup! errors: display more info about failed checks and policies
Browse files Browse the repository at this point in the history
  • Loading branch information
divarvel committed Nov 25, 2024
1 parent 6ffe3ac commit e56390f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions biscuit-auth/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ pub enum Signature {
pub enum Logic {
#[error("a rule provided by a block is producing a fact with unbound variables")]
InvalidBlockRule(u32, String),
#[error("{policy}, and the following checks failed: {checks:?}")]
#[error("{policy}, and the following checks failed: {}", display_failed_checks(.checks))]
Unauthorized {
/// the policy that matched
policy: MatchedPolicy,
Expand All @@ -182,7 +182,7 @@ pub enum Logic {
},
#[error("the authorizer already contains a token")]
AuthorizerNotEmpty,
#[error("no matching policy was found, and the following checks failed: {checks:?}")]
#[error("no matching policy was found, and the following checks failed: {}", display_failed_checks(.checks))]
NoMatchingPolicy {
/// list of checks that failed validation
checks: Vec<FailedCheck>,
Expand All @@ -208,6 +208,13 @@ pub enum FailedCheck {
Authorizer(FailedAuthorizerCheck),
}

fn display_failed_checks(c: &[FailedCheck]) -> String {
c.iter()
.map(|c| c.to_string())
.collect::<Vec<_>>()
.join(", ")
}

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde-error", derive(serde::Serialize, serde::Deserialize))]
pub struct FailedBlockCheck {
Expand Down

0 comments on commit e56390f

Please sign in to comment.