cloud_storage_lite/errors.rs
1//! Errors that occur while using this library.
2
3use thiserror::Error;
4
5pub use crate::api::GoogleError;
6
7/// An Error produced by this library.
8#[derive(Debug, Error)]
9pub enum Error {
10 /// An HTTP error occurred. If a not-unspecified error response is received, it
11 /// will be converted into a more specific `Error` variant. For instance, a 404
12 /// response will turn into `Error::NotFound`.
13 #[error("an http error occurred: {0}")]
14 Http(#[from] reqwest::Error),
15
16 /// The requested resource could not be found.
17 #[error(transparent)]
18 NotFound(#[from] NotFoundError),
19
20 /// The requested resource could not be fetched due to lack of permissions.
21 #[error("permission denied: {0}")]
22 PermissionDenied(String),
23
24 /// The GCP API returned some error that's not commonly encountered while using this library.
25 #[error(transparent)]
26 OtherGoogle(#[from] GoogleError),
27
28 /// The [`TokenProvider`] had an error.
29 #[error("couldn't fetch token: {0}")]
30 TokenFetch(anyhow::Error),
31}
32
33/// The specific thing that wasn't found.
34#[derive(Debug, Error)]
35pub enum NotFoundError {
36 /// The bucket wasn't found.
37 #[error("the bucket `{bucket}` was not found")]
38 Bucket {
39 /// The name of the bucket that wasn't found.
40 bucket: String,
41 },
42
43 /// An object wasn't found, but the bucket does exist.
44 #[error("the object `{bucket}/{key}` was not found")]
45 Object {
46 /// The name of the bucket from which the object was requested.
47 bucket: String,
48 /// The object key that wasn't found.
49 key: String,
50 },
51
52 /// Some other thing wasn't found.
53 #[error("{0}")]
54 Other(String),
55}