Skip to content

Commit

Permalink
feat(object_store): add PermissionDenied variant to top-level error (
Browse files Browse the repository at this point in the history
…#6194)

* feat(object_store):  add `PermissionDenied` variant to top-level error

* Update object_store/src/lib.rs

Co-authored-by: Raphael Taylor-Davies <1781103+tustvold@users.noreply.github.com>

* refactor: add additional error variant for unauthenticated ops

* fix: include path in unauthenticated error

---------

Co-authored-by: Raphael Taylor-Davies <1781103+tustvold@users.noreply.github.com>
  • Loading branch information
kyle-mccarthy and tustvold authored Aug 8, 2024
1 parent 4bd737d commit 130ba61
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
12 changes: 12 additions & 0 deletions object_store/src/client/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ impl Error {
path,
source: Box::new(self),
},
Some(StatusCode::FORBIDDEN) => crate::Error::PermissionDenied {
path,
source: Box::new(self),
},
Some(StatusCode::UNAUTHORIZED) => crate::Error::Unauthenticated {
path,
source: Box::new(self),
},
_ => crate::Error::Generic {
store,
source: Box::new(self),
Expand All @@ -106,6 +114,10 @@ impl From<Error> for std::io::Error {
status: StatusCode::BAD_REQUEST,
..
} => Self::new(ErrorKind::InvalidInput, err),
Error::Client {
status: StatusCode::UNAUTHORIZED | StatusCode::FORBIDDEN,
..
} => Self::new(ErrorKind::PermissionDenied, err),
Error::Reqwest { source, .. } if source.is_timeout() => {
Self::new(ErrorKind::TimedOut, err)
}
Expand Down
20 changes: 20 additions & 0 deletions object_store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,26 @@ pub enum Error {
#[snafu(display("Operation not yet implemented."))]
NotImplemented,

#[snafu(display(
"The operation lacked the necessary privileges to complete for path {}: {}",
path,
source
))]
PermissionDenied {
path: String,
source: Box<dyn std::error::Error + Send + Sync + 'static>,
},

#[snafu(display(
"The operation lacked valid authentication credentials for path {}: {}",
path,
source
))]
Unauthenticated {
path: String,
source: Box<dyn std::error::Error + Send + Sync + 'static>,
},

#[snafu(display("Configuration key: '{}' is not valid for store '{}'.", key, store))]
UnknownConfigurationKey { store: &'static str, key: String },
}
Expand Down

0 comments on commit 130ba61

Please sign in to comment.