http icon indicating copy to clipboard operation
http copied to clipboard

[src/error.rs] pub ErrorKind

Open SamuelMarks opened this issue 5 years ago • 2 comments

I'm confused how to percolate errors from http through my library.

I want to percolate up a http::uri::ErrorKind::InvalidFormat if .host() is None.

SamuelMarks avatar Apr 03 '20 11:04 SamuelMarks

The private http::error::ErrorKind shouldn't be in your way, since http::Error has is and get_ref for read access, and implements From<InvalidUri> (if "percolate" includes creating them). However, I see that http::uri::InvalidUri is itself opaque: not user constructable and only offers a description to read. Is that the real issue?

The prominent style here AFAICT, is to never expose a public enum. This unfortunately tends to leave users with only a description string, but #303 demonstrates willingness to improve usability in other ways. Perhaps kind-specific constructor functions and is_<kind>(&self) -> bool (e.g. is_invalid_format) methods could be added to InvalidUri?

dekellum avatar Apr 03 '20 15:04 dekellum

@dekellum So how do I create a http::uri::InvalidUri in my codebase?

SamuelMarks avatar Apr 03 '20 22:04 SamuelMarks