Skip to main content

secrets_rs/
error.rs

1/// Errors that can occur when parsing a secret URN string.
2#[derive(Debug, thiserror::Error, PartialEq)]
3pub enum UrnParseError {
4    #[error(
5        "URN must have exactly 4 colon-separated segments (urn:secrets-rs:<source_id>:<name>), got {0}"
6    )]
7    WrongSegmentCount(usize),
8
9    #[error("URN scheme must be 'urn', got '{0}'")]
10    InvalidScheme(String),
11
12    #[error("URN NID must be 'secrets-rs', got '{0}'")]
13    InvalidNid(String),
14
15    #[error("source_id must not be empty")]
16    EmptySourceId,
17
18    #[error("name must not be empty")]
19    EmptyName,
20}
21
22/// Errors produced by a [`crate::Source`] during secret retrieval.
23#[derive(Debug, thiserror::Error)]
24pub enum SourceError {
25    #[error("secret '{name}' not found in source")]
26    NotFound { name: String },
27
28    #[error("source error: {0}")]
29    Other(String),
30}
31
32/// Errors that can occur while binding a secret to its value.
33#[derive(Debug, thiserror::Error)]
34pub enum BindError {
35    #[error("no source registered with id '{source_id}'")]
36    SourceNotFound { source_id: String },
37
38    #[error("secret '{name}' not found in source '{source_id}'")]
39    NameNotFound { source_id: String, name: String },
40
41    #[error("type conversion failed for secret '{urn}': {detail}")]
42    TypeConversion { urn: String, detail: String },
43
44    #[error("source error for '{urn}': {source}")]
45    Source { urn: String, source: SourceError },
46}
47
48/// Error returned when the value of a [`crate::Secret`] is accessed before it has been bound.
49#[derive(Debug, thiserror::Error)]
50#[error("secret '{urn}' has not been bound; call bind() or bind_all() first")]
51pub struct UnboundError {
52    pub urn: String,
53}