olai_store/error.rs
1/// A convenience type for declaring Results in the resource store.
2pub type Result<T, E = Error> = std::result::Result<T, E>;
3
4/// Errors returned by the resource store, association store, and secret manager.
5///
6/// Store operations report failures through these variants; the doc comments on
7/// the [`ObjectStore`], [`AssociationStore`], and [`SecretManager`] trait methods
8/// note which variant a given method returns and when.
9///
10/// [`ObjectStore`]: crate::ObjectStore
11/// [`AssociationStore`]: crate::AssociationStore
12/// [`SecretManager`]: crate::SecretManager
13#[derive(Debug, thiserror::Error)]
14pub enum Error {
15 #[error("Entity not found.")]
16 NotFound,
17
18 #[error("Entity already exists.")]
19 AlreadyExists,
20
21 #[error("Invalid argument: {0}")]
22 InvalidArgument(String),
23
24 #[error("Invalid identifier: {0}")]
25 InvalidIdentifier(#[from] uuid::Error),
26
27 #[error("Generic error: {0}")]
28 Generic(String),
29
30 #[error(transparent)]
31 SerDe(#[from] serde_json::Error),
32}
33
34impl Error {
35 /// Constructs an [`Error::Generic`] from a message.
36 ///
37 /// Use this for failures that do not map onto a more specific variant.
38 pub fn generic(msg: impl Into<String>) -> Self {
39 Self::Generic(msg.into())
40 }
41
42 /// Constructs an [`Error::InvalidArgument`] from a message.
43 ///
44 /// Use this when a caller-supplied argument is malformed or out of range.
45 pub fn invalid_argument(msg: impl Into<String>) -> Self {
46 Self::InvalidArgument(msg.into())
47 }
48}