objectstore_client/error.rs
1use std::sync::Arc;
2
3/// Errors that can happen within the objectstore-client
4#[derive(Debug, thiserror::Error)]
5#[non_exhaustive]
6pub enum Error {
7 /// Any error emitted from the underlying [`reqwest`] client.
8 #[error(transparent)]
9 Reqwest(#[from] reqwest::Error),
10 /// IO errors related to payload streaming.
11 #[error(transparent)]
12 Io(#[from] std::io::Error),
13 /// Errors related to UTF-8 dcoding
14 #[error(transparent)]
15 Utf8(#[from] std::string::FromUtf8Error),
16 /// Errors handling metadata, such as serializing it to/from HTTP headers.
17 #[error(transparent)]
18 Metadata(#[from] objectstore_types::metadata::Error),
19 /// Error when scope validation fails.
20 #[error("invalid scope: {0}")]
21 InvalidScope(#[from] objectstore_types::scope::InvalidScopeError),
22 /// Error when creating auth tokens, such as invalid keys.
23 #[error(transparent)]
24 TokenError(#[from] jsonwebtoken::errors::Error),
25 /// Error when the permissions requested for a token exceed those granted to the
26 /// [`TokenGenerator`](crate::TokenGenerator).
27 #[error("requested permissions not granted to this token generator: {escalated:?}")]
28 PermissionEscalation {
29 /// The requested permissions that are not granted to the generator.
30 escalated: Vec<objectstore_types::auth::Permission>,
31 },
32 /// Error when per-token permission or expiry overrides are requested for a static
33 /// (pre-signed) token, which cannot be re-scoped.
34 #[error("static tokens cannot be re-scoped with custom permissions or expiry")]
35 StaticTokenOverride,
36 /// Error when URL manipulation fails.
37 #[error("{message}")]
38 InvalidUrl {
39 /// The URL error message.
40 message: String,
41 },
42 /// Error when parsing a multipart response.
43 #[error(transparent)]
44 Multipart(#[from] multer::Error),
45 /// Error when the server returned a malformed response.
46 #[error("{0}")]
47 MalformedResponse(String),
48 /// Error that indicates that an entire batch request failed.
49 #[error("batch request failed: {0}")]
50 Batch(Arc<Error>),
51 /// Error that indicates failure of an individual operation in a batch request.
52 #[error("operation failed with HTTP status code {status}: {message}")]
53 OperationFailure {
54 /// The HTTP status code corresponding to the status of the operation.
55 status: u16,
56 /// The error message.
57 message: String,
58 },
59 /// A resumable upload session expired, was canceled, or could otherwise not be found.
60 #[cfg(feature = "resumable-upload-api")]
61 #[error("resumable upload session is not available")]
62 ResumableUploadUnavailable,
63 /// A resumable chunk starts at a different offset than the server currently holds.
64 #[cfg(feature = "resumable-upload-api")]
65 #[error("upload offset mismatch (server holds {offset} bytes)")]
66 UploadOffsetMismatch {
67 /// The server's authoritative upload offset in bytes.
68 offset: u64,
69 },
70 /// A non-final chunk is shorter than the upload granularity.
71 #[cfg(feature = "resumable-upload-api")]
72 #[error(
73 "non-final chunk {chunk_length} is smaller than upload granularity {upload_granularity}"
74 )]
75 ChunkTooSmall {
76 /// The declared length of the chunk.
77 chunk_length: u64,
78 /// The upload granularity in bytes.
79 upload_granularity: u64,
80 },
81}
82
83/// A convenience alias that defaults our [`Error`] type.
84pub type Result<T, E = Error> = std::result::Result<T, E>;