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

xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new 778573f85 refactor(bindings/java): explict error handling (#3288)
778573f85 is described below

commit 778573f85b64c77abdb3dfd60fe49db096cabec9
Author: tison <[email protected]>
AuthorDate: Sun Oct 15 23:55:36 2023 +0800

    refactor(bindings/java): explict error handling (#3288)
    
    Signed-off-by: tison <[email protected]>
---
 bindings/java/src/error.rs | 26 ++++----------------------
 bindings/java/src/lib.rs   |  4 +++-
 2 files changed, 7 insertions(+), 23 deletions(-)

diff --git a/bindings/java/src/error.rs b/bindings/java/src/error.rs
index b22a85302..7ee42e81e 100644
--- a/bindings/java/src/error.rs
+++ b/bindings/java/src/error.rs
@@ -29,12 +29,6 @@ pub(crate) struct Error {
 }
 
 impl Error {
-    pub(crate) fn unexpected(err: impl Into<anyhow::Error> + Display) -> Error 
{
-        Error {
-            inner: opendal::Error::new(ErrorKind::Unexpected, 
&err.to_string()).set_source(err),
-        }
-    }
-
     pub(crate) fn throw(&self, env: &mut JNIEnv) {
         if let Err(err) = self.do_throw(env) {
             match err {
@@ -84,26 +78,14 @@ impl Error {
 }
 
 impl From<opendal::Error> for Error {
-    fn from(error: opendal::Error) -> Self {
-        Self { inner: error }
+    fn from(err: opendal::Error) -> Self {
+        Self { inner: err }
     }
 }
 
 impl From<jni::errors::Error> for Error {
-    fn from(error: jni::errors::Error) -> Self {
-        Error::unexpected(error)
-    }
-}
-
-impl From<std::str::Utf8Error> for Error {
-    fn from(error: std::str::Utf8Error) -> Self {
-        Error::unexpected(error)
-    }
-}
-
-impl From<std::string::FromUtf8Error> for Error {
-    fn from(error: std::string::FromUtf8Error) -> Self {
-        Error::unexpected(error)
+    fn from(err: jni::errors::Error) -> Self {
+        opendal::Error::new(ErrorKind::Unexpected, &err.to_string()).into()
     }
 }
 
diff --git a/bindings/java/src/lib.rs b/bindings/java/src/lib.rs
index 63adbb35b..97c6d0c53 100644
--- a/bindings/java/src/lib.rs
+++ b/bindings/java/src/lib.rs
@@ -135,7 +135,9 @@ fn make_presigned_request<'a>(env: &mut JNIEnv<'a>, req: 
PresignedRequest) -> Re
         let mut map = HashMap::new();
         for (k, v) in req.header().iter() {
             let key = k.to_string();
-            let value = v.to_str().map_err(Error::unexpected)?;
+            let value = v.to_str().map_err(|err| {
+                opendal::Error::new(opendal::ErrorKind::Unexpected, 
&err.to_string())
+            })?;
             map.insert(key, value.to_owned());
         }
         map

Reply via email to