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

Refactor ParseError #1089

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

nepalez
Copy link
Contributor

@nepalez nepalez commented Aug 14, 2023

This PR is a part of error specialization initiated by the #1047

See the initial discussion of the change in this #1081 (to be removed later, after processing the feedback by @Jarema and creating smaller PR-s from its commits).

This particular PR is created to follow-up the discussion


In this PR instead of the crate::Error, the method stream::parse_headers will return the specialized error with kind enumerating the possible causes of parsing errors. This change will help to specialize errors error returned by public methods.

Along this change, I also refactored 2 errors, namely the ParseHeaderNameError and the ParseHeaderValueError to convert them to specialization of generic crate::error::Error<_>.

These changes are collected in the same commit because all of them describe errors occurred during either building or parsing headers.

@@ -339,19 +340,26 @@ impl HeaderValue {
}
}

#[derive(Debug, Clone)]
pub struct ParseHeaderValueError;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are intended to be discrete simple errors for FromStr, they live outside of the "io-esque" methods on context and client.

This complicates what is a very simple and straight forward discrete error type imo.
Remember, users are the ones calling "".parse() directly for the most part.

Instead of the `crate::Error`, the <private> method `stream::parse_headers`
will return the specialized error with kind enumerating the possible
causes of parsing errors. This change will help to specialize errors
error returned by public methods.

Along this change, I also refactored 2 errors, namely
the `ParseHeaderNameError` and the `ParseHeaderValueError`
to convert them to specialization of generic `crate::error::Error<_>`.

These changes are collected in the same commit because all of them
describe errors occurred during either building or parsing headers.
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 this pull request may close these issues.

None yet

2 participants