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

More specific error types #16

Closed
not-my-profile opened this issue Dec 10, 2021 · 7 comments
Closed

More specific error types #16

not-my-profile opened this issue Dec 10, 2021 · 7 comments
Assignees
Milestone

Comments

@not-my-profile
Copy link

Hey, thanks for your library :) I want to use the manual slicing methods but noticed that they all return the ReadError enum, which contains variants that cannot actually occur.

For example with Ethernet2HeaderSlice.from_slice the only error variant that can actually occur is UnexpectedEndOfSlice.

Would you accept a PR changing ReadError to something like the following?

pub enum ReadError {
    IoError(Error),
    UnexpectedEndOfSlice(UnexpectedEndOfSliceError),
    DoubleVlan(DoubleVlanError),
    IpUnsupportedVersion(u8),
    Ipv4(Ipv4Error),
    Ipv6(Ipv6Error),
    IpAuthenticationHeader(IpAuthenticationHeaderError),
    Tcp(TcpError),
}
  • Ethernet2HeaderSlice.from_slice would then return a Result<Ethernet2HeaderSlice<'a>, UnexpectedEndOfSliceError>
  • Ipv4HeaderSlice.from_slice would then return a Result<Ipv4HeaderSlice<'a>, Ipv4Error>
  • etc.
@JulianSchmid
Copy link
Owner

Hi @not-my-profile,

That is a good idea. We could even add a From implementation to enable auto conversion to read error to be backwards compatible.

Greets
Julian

@JulianSchmid
Copy link
Owner

Would you accept a PR changing ReadError to something like the following?

Yes of course. But I can not guarantee you how fast I can merge it. Last time one week escalated into 2 years, but I don't think this will happen with this :) .

Greets
Julian

@not-my-profile
Copy link
Author

Thanks, for the quick answer :) Could you format your code with cargo fmt beforehand?

@JulianSchmid
Copy link
Owner

I decided agains using rust fmt in this library as it made the testcases where raw bytes are used harder to read (e.g.

KIND_NOOP,
).

@not-my-profile
Copy link
Author

not-my-profile commented Dec 12, 2021

Ah yeah ... adding #[rustfmt::skip] everywhere is cumbersome and #![rustfmt::skip] doesn't work on stable yet.

@JulianSchmid
Copy link
Owner

Hi, I had a closer look at the error types and I will probably restructure them quite a bit in the next release. Specifically also splitting them up based on the operation: read, from_slice, write, to_slice. At the same time I will try to split the error types so that an operation only returns an error type with values it can actually trigger.

That should hopefully also resolve your request, but will allow me to separate std::io::Error from the rest. std::io::Error has always been a bit of a thorn in my side, as it does not implement Eq or PartialEq (which makes writing tests a bit more verbose). Additionally std::io::Error is not available when building with no_std, which I really would like to support.

@JulianSchmid JulianSchmid added this to the v0.11 milestone Dec 24, 2021
@JulianSchmid JulianSchmid modified the milestones: v0.11, v0.12, v0.13 Jul 17, 2022
@JulianSchmid JulianSchmid modified the milestones: v0.13, v0.15 Dec 17, 2022
@JulianSchmid JulianSchmid modified the milestones: v0.15, v0.14 Mar 27, 2023
@JulianSchmid JulianSchmid self-assigned this Apr 12, 2023
@JulianSchmid
Copy link
Owner

Finalized by #64

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

Successfully merging a pull request may close this issue.

2 participants