New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(java): refactor error handling #2325
Conversation
java/core/lance-jni/src/error.rs
Outdated
IllegalArgumentException, | ||
IOException, | ||
RuntimeException, | ||
pub type JavaResult<T> = std::result::Result<T, JavaError>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LuQQiu can we add tests to capture those errors? Specifically, whether the clear error message is presented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We usually just name this as
type Result<T> = std::result::Result<T, Error>`
Struct Error {
...}
So, within this crate, it still reads in a style that is consistent with a Rust project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to mimic the Python side, turn Result finally to a special end Result
java/core/lance-jni/src/error.rs
Outdated
} | ||
#[derive(Debug)] | ||
pub struct JavaError { | ||
message: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as @wjones127 pointed out in #2316, to get more precise error info, it might be better to put a BoxedError here. like
#[derive(Debug)]
pub struct JavaError {
source: BoxedError,
java_class: JavaExceptionClass,
}
BoxedError is defined here:
BoxedError
I haven't read much of the Lance codebase, correct me if I'm wrong
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@broccoliSpicy Good to know about the BoxedError and its benefits! Thanks for the knowledge transfer!
For java side, this JavaError is a last mile error to the user, which translates the LanceError into Java Error with string message.
The information in the BoxedError will be included in this String message
e.g. In lance Error,
#[snafu(display("Dataset at path {path} was not found: {source}, {location}"))]
DatasetNotFound {
path: String,
source: BoxedError,
location: Location,
},
on java side we directly call LanceError.toString() to get the message with source information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LuQQiu glad to know how error message is transfered from lance to jave, thanks!
@QianZhu PTAL, thanks! |
@QianZhu Added some test cases
|
java/core/lance-jni/src/error.rs
Outdated
fn infer_error(self) -> JavaResult<T>; | ||
} | ||
|
||
impl<T> JavaErrorExt<T> for std::result::Result<T, LanceError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is first time i saw the conversion on Result instead of Error. Why do we do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mimic the Python side to reduce the error conversion headache, we do not need to list out all the errors and create the message for each error again, makes the error conversion much easier (keep the original info while can convert to target java exception)
java/core/lance-jni/src/error.rs
Outdated
#[snafu(display("Unknown error: {message}, {location}"))] | ||
Other { message: String, location: Location }, | ||
#[derive(Debug)] | ||
pub struct JavaError { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets just name this to Error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to mimic PyResult and PyErr lol
represent a special kind of end result/error
Refactor the error handling to map errors (with an ErrorExt trait) following Lance Python convention