Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 4 additions & 22 deletions bindings/java/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
}
}

Expand Down
4 changes: 3 additions & 1 deletion bindings/java/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Comment thread
Xuanwo marked this conversation as resolved.
})?;
map.insert(key, value.to_owned());
}
map
Expand Down