objectstore_client/error.rs
1use std::sync::Arc;
2
3/// Errors that can happen within the objectstore-client
4#[derive(Debug, thiserror::Error)]
5pub enum Error {
6 /// Any error emitted from the underlying [`reqwest`] client.
7 #[error(transparent)]
8 Reqwest(#[from] reqwest::Error),
9 /// IO errors related to payload streaming.
10 #[error(transparent)]
11 Io(#[from] std::io::Error),
12 /// Errors related to UTF-8 dcoding
13 #[error(transparent)]
14 Utf8(#[from] std::string::FromUtf8Error),
15 /// Errors handling metadata, such as serializing it to/from HTTP headers.
16 #[error(transparent)]
17 Metadata(#[from] objectstore_types::metadata::Error),
18 /// Error when scope validation fails.
19 #[error("invalid scope: {0}")]
20 InvalidScope(#[from] objectstore_types::scope::InvalidScopeError),
21 /// Error when creating auth tokens, such as invalid keys.
22 #[error(transparent)]
23 TokenError(#[from] jsonwebtoken::errors::Error),
24 /// Error when the permissions requested for a token exceed those granted to the
25 /// [`TokenGenerator`](crate::TokenGenerator).
26 #[error("requested permissions not granted to this token generator: {escalated:?}")]
27 PermissionEscalation {
28 /// The requested permissions that are not granted to the generator.
29 escalated: Vec<objectstore_types::auth::Permission>,
30 },
31 /// Error when per-token permission or expiry overrides are requested for a static
32 /// (pre-signed) token, which cannot be re-scoped.
33 #[error("static tokens cannot be re-scoped with custom permissions or expiry")]
34 StaticTokenOverride,
35 /// Error when URL manipulation fails.
36 #[error("{message}")]
37 InvalidUrl {
38 /// The URL error message.
39 message: String,
40 },
41 /// Error when parsing a multipart response.
42 #[error(transparent)]
43 Multipart(#[from] multer::Error),
44 /// Error when the server returned a malformed response.
45 #[error("{0}")]
46 MalformedResponse(String),
47 /// Error that indicates that an entire batch request failed.
48 #[error("batch request failed: {0}")]
49 Batch(Arc<Error>),
50 /// Error that indicates failure of an individual operation in a batch request.
51 #[error("operation failed with HTTP status code {status}: {message}")]
52 OperationFailure {
53 /// The HTTP status code corresponding to the status of the operation.
54 status: u16,
55 /// The error message.
56 message: String,
57 },
58 /// Error when part number validation fails (must be >= 1).
59 #[error("invalid part number: {0}")]
60 InvalidPartNumber(u32),
61 /// Error when upload ID validation fails.
62 #[error(transparent)]
63 InvalidUploadId(#[from] objectstore_types::multipart::InvalidUploadId),
64 /// Error returned when attempting to complete a multipart upload.
65 #[error("multipart complete failed ({code}): {message}")]
66 MultipartComplete {
67 /// The error code or kind.
68 code: String,
69 /// The error message.
70 message: String,
71 },
72}
73
74/// A convenience alias that defaults our [`Error`] type.
75pub type Result<T, E = Error> = std::result::Result<T, E>;