This is an automated email from the ASF dual-hosted git repository.

tustvold pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/master by this push:
     new 130ba61e3 feat(object_store):  add `PermissionDenied` variant to 
top-level error (#6194)
130ba61e3 is described below

commit 130ba61e35a3b5ba0a7932bc2ffed38af09f6d4e
Author: Kyle McCarthy <[email protected]>
AuthorDate: Thu Aug 8 12:45:14 2024 -0500

    feat(object_store):  add `PermissionDenied` variant to top-level error 
(#6194)
    
    * feat(object_store):  add `PermissionDenied` variant to top-level error
    
    * Update object_store/src/lib.rs
    
    Co-authored-by: Raphael Taylor-Davies 
<[email protected]>
    
    * refactor: add additional error variant for unauthenticated ops
    
    * fix: include path in unauthenticated error
    
    ---------
    
    Co-authored-by: Raphael Taylor-Davies 
<[email protected]>
---
 object_store/src/client/retry.rs | 12 ++++++++++++
 object_store/src/lib.rs          | 20 ++++++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/object_store/src/client/retry.rs b/object_store/src/client/retry.rs
index 5df4ce059..1fc689cdf 100644
--- a/object_store/src/client/retry.rs
+++ b/object_store/src/client/retry.rs
@@ -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),
@@ -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)
             }
diff --git a/object_store/src/lib.rs b/object_store/src/lib.rs
index 7699477b9..4184d58a0 100644
--- a/object_store/src/lib.rs
+++ b/object_store/src/lib.rs
@@ -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 },
 }

Reply via email to