You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by "tisonkun (via GitHub)" <gi...@apache.org> on 2023/10/15 14:27:27 UTC

[PR] feat(bindings/java): always convey backtrace on exception [incubator-opendal]

tisonkun opened a new pull request, #3286:
URL: https://github.com/apache/incubator-opendal/pull/3286

   I'm not sure if it's better to expose a method said `display(force_backtrace: bool)` in `opendal::Error`/


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(bindings/java): always convey backtrace on exception [incubator-opendal]

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #3286:
URL: https://github.com/apache/incubator-opendal/pull/3286#discussion_r1359889803


##########
bindings/java/src/error.rs:
##########
@@ -115,7 +124,13 @@ impl Debug for Error {
 
 impl Display for Error {
     fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
-        Display::fmt(&self.inner, f)
+        Display::fmt(&self.inner, f)?;
+        if self.backtrace.status() == BacktraceStatus::Captured {

Review Comment:
   `opendal::Error` implements `Display` and `Debug` very carefully, how about doing the same thing for java binding's error?



##########
bindings/java/src/error.rs:
##########
@@ -15,26 +15,34 @@
 // specific language governing permissions and limitations
 // under the License.
 
+use std::backtrace::{Backtrace, BacktraceStatus};
 use std::fmt::Debug;
 use std::fmt::Display;
 use std::fmt::Formatter;
 
 use jni::objects::JThrowable;
 use jni::objects::JValue;
 use jni::JNIEnv;
+
 use opendal::ErrorKind;
 
 pub(crate) struct Error {
     inner: opendal::Error,
+    backtrace: Backtrace,
 }
 
 impl Error {
-    pub(crate) fn unexpected(err: impl Into<anyhow::Error> + Display) -> Error {
+    pub(crate) fn new(inner: opendal::Error) -> Error {
         Error {
-            inner: opendal::Error::new(ErrorKind::Unexpected, &err.to_string()).set_source(err),
+            inner,
+            backtrace: Backtrace::capture(),
         }
     }
 
+    pub(crate) fn unexpected(err: impl Into<anyhow::Error> + Display) -> Error {

Review Comment:
   Accept an `impl Into<anyhow::Error>` seems not cool. `opendal::Error` will capture the backtrace while creating. How about accpet a simple `&str` instead?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(bindings/java): always convey backtrace on exception [incubator-opendal]

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on code in PR #3286:
URL: https://github.com/apache/incubator-opendal/pull/3286#discussion_r1359896204


##########
bindings/java/src/error.rs:
##########
@@ -15,26 +15,34 @@
 // specific language governing permissions and limitations
 // under the License.
 
+use std::backtrace::{Backtrace, BacktraceStatus};
 use std::fmt::Debug;
 use std::fmt::Display;
 use std::fmt::Formatter;
 
 use jni::objects::JThrowable;
 use jni::objects::JValue;
 use jni::JNIEnv;
+
 use opendal::ErrorKind;
 
 pub(crate) struct Error {
     inner: opendal::Error,
+    backtrace: Backtrace,
 }
 
 impl Error {
-    pub(crate) fn unexpected(err: impl Into<anyhow::Error> + Display) -> Error {
+    pub(crate) fn new(inner: opendal::Error) -> Error {
         Error {
-            inner: opendal::Error::new(ErrorKind::Unexpected, &err.to_string()).set_source(err),
+            inner,
+            backtrace: Backtrace::capture(),
         }
     }
 
+    pub(crate) fn unexpected(err: impl Into<anyhow::Error> + Display) -> Error {

Review Comment:
   This is conveied from `pub fn set_source(mut self, src: impl Into<anyhow::Error>) -> Self {`. I want to set the source error.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(bindings/java): always convey backtrace on exception [incubator-opendal]

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on code in PR #3286:
URL: https://github.com/apache/incubator-opendal/pull/3286#discussion_r1359895196


##########
bindings/java/src/error.rs:
##########
@@ -15,26 +15,34 @@
 // specific language governing permissions and limitations
 // under the License.
 
+use std::backtrace::{Backtrace, BacktraceStatus};
 use std::fmt::Debug;
 use std::fmt::Display;
 use std::fmt::Formatter;
 
 use jni::objects::JThrowable;
 use jni::objects::JValue;
 use jni::JNIEnv;
+
 use opendal::ErrorKind;
 
 pub(crate) struct Error {
     inner: opendal::Error,
+    backtrace: Backtrace,
 }
 
 impl Error {
-    pub(crate) fn unexpected(err: impl Into<anyhow::Error> + Display) -> Error {
+    pub(crate) fn new(inner: opendal::Error) -> Error {
         Error {
-            inner: opendal::Error::new(ErrorKind::Unexpected, &err.to_string()).set_source(err),
+            inner,
+            backtrace: Backtrace::capture(),
         }
     }
 
+    pub(crate) fn unexpected(err: impl Into<anyhow::Error> + Display) -> Error {

Review Comment:
   Let's investigate this in another thread. I suggest it's a larger issue to dig and can cause a large amount of error handling code refactor.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(bindings/java): always convey backtrace on exception [incubator-opendal]

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on code in PR #3286:
URL: https://github.com/apache/incubator-opendal/pull/3286#discussion_r1359895782


##########
bindings/java/src/error.rs:
##########
@@ -115,7 +124,13 @@ impl Debug for Error {
 
 impl Display for Error {
     fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
-        Display::fmt(&self.inner, f)
+        Display::fmt(&self.inner, f)?;
+        if self.backtrace.status() == BacktraceStatus::Captured {

Review Comment:
   Out of curiousity, when does `if f.alternate()` hit?
   
   UPDATE - I found it's when `{:#?}`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(bindings/java): always convey backtrace on exception [incubator-opendal]

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on code in PR #3286:
URL: https://github.com/apache/incubator-opendal/pull/3286#discussion_r1359895782


##########
bindings/java/src/error.rs:
##########
@@ -115,7 +124,13 @@ impl Debug for Error {
 
 impl Display for Error {
     fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
-        Display::fmt(&self.inner, f)
+        Display::fmt(&self.inner, f)?;
+        if self.backtrace.status() == BacktraceStatus::Captured {

Review Comment:
   Out of curiousity, when does `if f.alternate()` hit?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(bindings/java): always convey backtrace on exception [incubator-opendal]

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on code in PR #3286:
URL: https://github.com/apache/incubator-opendal/pull/3286#discussion_r1359896784


##########
bindings/java/src/error.rs:
##########
@@ -15,26 +15,34 @@
 // specific language governing permissions and limitations
 // under the License.
 
+use std::backtrace::{Backtrace, BacktraceStatus};
 use std::fmt::Debug;
 use std::fmt::Display;
 use std::fmt::Formatter;
 
 use jni::objects::JThrowable;
 use jni::objects::JValue;
 use jni::JNIEnv;
+
 use opendal::ErrorKind;
 
 pub(crate) struct Error {
     inner: opendal::Error,
+    backtrace: Backtrace,
 }
 
 impl Error {
-    pub(crate) fn unexpected(err: impl Into<anyhow::Error> + Display) -> Error {
+    pub(crate) fn new(inner: opendal::Error) -> Error {
         Error {
-            inner: opendal::Error::new(ErrorKind::Unexpected, &err.to_string()).set_source(err),
+            inner,
+            backtrace: Backtrace::capture(),
         }
     }
 
+    pub(crate) fn unexpected(err: impl Into<anyhow::Error> + Display) -> Error {

Review Comment:
   But it seems we also use the Display format for these sources only. I have an idea for improving this situation. Let's just do it in another thread.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(bindings/java): always convey backtrace on exception [incubator-opendal]

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on PR #3286:
URL: https://github.com/apache/incubator-opendal/pull/3286#issuecomment-1763421069

   Updated.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(bindings/java): always convey backtrace on exception [incubator-opendal]

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on code in PR #3286:
URL: https://github.com/apache/incubator-opendal/pull/3286#discussion_r1359895131


##########
bindings/java/src/error.rs:
##########
@@ -115,7 +124,13 @@ impl Debug for Error {
 
 impl Display for Error {
     fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
-        Display::fmt(&self.inner, f)
+        Display::fmt(&self.inner, f)?;
+        if self.backtrace.status() == BacktraceStatus::Captured {

Review Comment:
   This is not the major issue here. I implemented `Display` and `Debug` for Java binding's Error also, but I'd prefer to use Display with backtrace. Most of what I need is Display's result, only the backtrace is necessary for this binding debugging requirement.
   
   You can pull the code to check the full impl.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(bindings/java): always convey backtrace on exception [incubator-opendal]

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on code in PR #3286:
URL: https://github.com/apache/incubator-opendal/pull/3286#discussion_r1359895723


##########
bindings/java/src/error.rs:
##########
@@ -115,7 +124,13 @@ impl Debug for Error {
 
 impl Display for Error {
     fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
-        Display::fmt(&self.inner, f)
+        Display::fmt(&self.inner, f)?;
+        if self.backtrace.status() == BacktraceStatus::Captured {

Review Comment:
   Seems using debug meets what I need here. I'll change the impl now.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(bindings/java): convey backtrace on exception [incubator-opendal]

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo merged PR #3286:
URL: https://github.com/apache/incubator-opendal/pull/3286


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org