Skip to content
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

Error Handling in 0.8 #1139

Closed
3 tasks done
Tracked by #671
jswrenn opened this issue Apr 24, 2024 · 0 comments
Closed
3 tasks done
Tracked by #671

Error Handling in 0.8 #1139

jswrenn opened this issue Apr 24, 2024 · 0 comments
Assignees

Comments

@jswrenn
Copy link
Collaborator

jswrenn commented Apr 24, 2024

Overview

Zerocopy's deserialization methods will return Result instead of Option. The Err type of the Result will provide:

  • the cause of the deserialization error
  • access to the un-deserializable bytes

Motivation

Providing better error messages

As it stands, .unwrap() presently produces an uninformative error message. Using a custom error type will allow us to provide precise diagnostic text.

Providing programatic access to the cause of the failure

The bytemuck crate provides this information with its PodCastError type. A cursory search of Github suggests that this fidelity is useful to some customers.

Providing the original bytes

Our current API does not always provide access to the original bytes in the case of deserialization failure. For instance, attempting this:

loop {
    let Some((des, rem)) = T::mut_from_prefix(buffer) else {
        panic!("could not parse from {buffer:?}");
    };
    buffer = rem;
}

...produces this error message:

error[E0502]: cannot borrow `buffer` as immutable because it is also borrowed as mutable
 --> src/main.rs:9:38
  |
8 |     let Some((d, remainder)) = mut_from_prefix_split::<u8>(buffer) else {
  |                                                            ------ mutable borrow occurs here
9 |         panic!("could not parse from {buffer:?}");
  |                                      ^^^^^^^^^^
  |                                      |
  |                                      immutable borrow occurs here
  |                                      mutable borrow later used here

Steps

@jswrenn jswrenn self-assigned this Apr 24, 2024
@joshlf joshlf mentioned this issue Apr 24, 2024
87 tasks
jswrenn added a commit that referenced this issue May 2, 2024
This PR overhauls error reporting, replacing our `Option` returns
with `Result`s. The `Err` type of these results provide both the
cause of the failure, and access to the underlying source of the
conversion.

Makes progress towards #1139.
jswrenn added a commit that referenced this issue May 2, 2024
This PR overhauls error reporting, replacing our `Option` returns
with `Result`s. The `Err` type of these results provide both the
cause of the failure, and access to the underlying source of the
conversion.

Makes progress towards #1139.
jswrenn added a commit that referenced this issue May 2, 2024
This PR overhauls error reporting, replacing our `Option` returns
with `Result`s. The `Err` type of these results provide both the
cause of the failure, and access to the underlying source of the
conversion.

Makes progress towards #1139.
jswrenn added a commit that referenced this issue May 3, 2024
This PR overhauls error reporting, replacing our `Option` returns
with `Result`s. The `Err` type of these results provide both the
cause of the failure, and access to the underlying source of the
conversion.

Makes progress towards #1139.
jswrenn added a commit that referenced this issue May 3, 2024
This PR overhauls error reporting, replacing our `Option` returns
with `Result`s. The `Err` type of these results provide both the
cause of the failure, and access to the underlying source of the
conversion.

Makes progress towards #1139.
github-merge-queue bot pushed a commit that referenced this issue May 3, 2024
This PR overhauls error reporting, replacing our `Option` returns
with `Result`s. The `Err` type of these results provide both the
cause of the failure, and access to the underlying source of the
conversion.

Makes progress towards #1139.
jswrenn added a commit that referenced this issue May 6, 2024
This make's `Unalign`'s methods consistent with zerocopy's other
methods, and, in the case of `Unalign::try_deref_mut`, allows the
original `&mut Unalign<T>` to be reused in the event of failure.

Makes progress towards #1139
jswrenn added a commit that referenced this issue May 6, 2024
This make's `Unalign`'s methods consistent with zerocopy's other
methods, and, in the case of `Unalign::try_deref_mut`, allows the
original `&mut Unalign<T>` to be reused in the event of failure.

Makes progress towards #1139
jswrenn added a commit that referenced this issue May 6, 2024
This make's `Unalign`'s methods consistent with zerocopy's other
methods, and, in the case of `Unalign::try_deref_mut`, allows the
original `&mut Unalign<T>` to be reused in the event of failure.

Makes progress towards #1139
github-merge-queue bot pushed a commit that referenced this issue May 6, 2024
This make's `Unalign`'s methods consistent with zerocopy's other
methods, and, in the case of `Unalign::try_deref_mut`, allows the
original `&mut Unalign<T>` to be reused in the event of failure.

Makes progress towards #1139
@joshlf joshlf closed this as completed May 10, 2024
jswrenn added a commit that referenced this issue May 17, 2024
This permits matching on the error variant, and ensures that the
variants are rendered in rustdoc.

Makes progress on #1139.
jswrenn added a commit that referenced this issue May 17, 2024
This permits matching on the error variant, and ensures that the
variants are rendered in rustdoc.

Makes progress on #1139.
jswrenn added a commit that referenced this issue May 17, 2024
This permits matching on the error variant, and ensures that the
variants are rendered in rustdoc.

Makes progress on #1139.
github-merge-queue bot pushed a commit that referenced this issue May 17, 2024
This permits matching on the error variant, and ensures that the
variants are rendered in rustdoc.

Makes progress on #1139.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants