Skip to main content

gatekeep_keepsake/
error.rs

1use gatekeep::{FactId, GatekeepError, SubjectSlot};
2use keepsake::KeepsakeError;
3use thiserror::Error;
4
5/// Backend error emitted by [`crate::KeepsakeResolver`].
6#[derive(Debug, Error)]
7pub enum KeepsakeResolveError<E> {
8    /// Gatekeep rejected the resolver source provenance.
9    #[error(transparent)]
10    Provenance(#[from] gatekeep::TenantBindingError),
11    /// The source returned facts outside the requested scope.
12    #[error("keepsake source returned a mismatched scope")]
13    ScopeMismatch,
14    /// Effective state cannot be established from the supplied evidence.
15    #[error(transparent)]
16    Effective(#[from] keepsake::EffectiveRelationError),
17    /// Gatekeep and keepsake subject validation drifted apart.
18    #[error(transparent)]
19    Subject(#[from] KeepsakeError),
20    /// The active-relation source failed.
21    #[error("keepsake relation source failed")]
22    Source(#[source] E),
23    /// Gatekeep refused a constructed known-fact bundle.
24    #[error(transparent)]
25    Gatekeep(#[from] GatekeepError),
26}
27
28/// Errors returned while resolving a gatekeep fact into a keepsake target.
29#[derive(Debug, Error, Clone, PartialEq, Eq)]
30pub enum KeepsakeTargetError {
31    /// The resolver has no binding for the requested fact.
32    #[error("no keepsake binding configured for fact {fact}")]
33    MissingBinding {
34        /// Unbound fact id.
35        fact: FactId,
36    },
37
38    /// The binding targets a request-scoped subject slot missing from the context.
39    #[error("context is missing subject slot {slot} for fact {fact}")]
40    MissingSubjectSlot {
41        /// Fact whose binding needs the subject.
42        fact: FactId,
43        /// Missing subject slot.
44        slot: SubjectSlot,
45    },
46
47    /// Gatekeep and keepsake subject validation drifted apart.
48    #[error("keepsake subject validation failed for fact {fact}")]
49    Subject {
50        /// Fact whose target subject could not be built.
51        fact: FactId,
52        /// Validation failure from keepsake.
53        #[source]
54        source: KeepsakeError,
55    },
56
57    /// Gatekeep's validated tenant could not be represented as a keepsake
58    /// tenant identity.
59    #[error("keepsake tenant validation failed for fact {fact}")]
60    Tenant {
61        /// Fact whose tenant conversion failed.
62        fact: FactId,
63        /// Validation failure from keepsake.
64        #[source]
65        source: KeepsakeError,
66    },
67}