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
InvalidUri
errors could probably include the invalid bytes
#571
Comments
Would it make sense in the display to limit the amount of viewable bytes? That said, I think this makes sense to me. |
Yeah, we probably want to have some kind of "common sense limit" on how much of the URI we print... |
On the one hand, better errors are a great user-centric improvement, I love em! If there's a way to improve it for users, even just some of the time, that'd be wonderful. On the other hand, here's some concerns we'd need to overcome:
|
Hmm, don't the parsing methods that take a slice convert the slice into a Lines 713 to 715 in 34a9d6b
If I understand the code correctly, it looks like all paths that construct a
This is a valid concern --- perhaps we would want to add a method to the |
To elaborate on the motivation here a bit, the particular use-case I'm thinking of with this feature request is one where the errors are being returned by a For applications where the primary interaction with URI parsing is passing a user input that might be a URI into |
Uh, well, woops. That could be improved...
Making better error messages is already splendid motivation, I didn't mean to seem against the idea. I think we should always help people understand what went wrong. Just wanted to make sure we didn't miss anything while doing so. |
Hmm, if we're planning to change those functions to only copy the bytes into a
We're in agreement on that --- you didn't come off as against it at all! I also want to consider all the possible reasons we shouldn't do this. I mainly thought it was worth explaining the motivation in order to see whether there might be other ways to surface invalid inputs in that don't have the same drawbacks as always including it in the error (e.g. some kind of new API in Hyper?)... |
Quick ping on this, I'd be happy to open a PR to add it if we can come to consensus on the constraints! |
The
InvalidUri
error type is returned when trying to parse an input as a URI, if the bytes are not a valid URI. This error type does not contain the value that we were trying to parse, but does indicate how the input was invalid.Since all methods of parsing a value as a
Uri
either take aBytes
or convert the input (string or byte slice) into aBytes
, the error type probably could include the input, and format it as part of theirfmt::Display
/fmt::Debug
implementations.Uri::from_shared
takes aBytes
by value, so returning it in the error value shouldn't have a significant performance cost --- if we're trying to parse a URI from an&str
or&[u8]
, we will have already copied it in order to convert it into aBytes
, and if the input was itself aBytes
, the reference count has already been incremented in order to callUri::from_shared
.This would make it much easier for an application to display the invalid input to the user, which is desirable, especially in cases where the invalid URI came from user input.
The text was updated successfully, but these errors were encountered: