Skip to content

Refactor ParseError#1089

Open
nepalez wants to merge 1 commit into
nats-io:mainfrom
nepalez:specialize-parse-errors
Open

Refactor ParseError#1089
nepalez wants to merge 1 commit into
nats-io:mainfrom
nepalez:specialize-parse-errors

Conversation

@nepalez

@nepalez nepalez commented Aug 14, 2023

Copy link
Copy Markdown
Contributor

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.

@nepalez nepalez force-pushed the specialize-parse-errors branch from 4a990c5 to ec2546c Compare August 14, 2023 19:09
Comment thread async-nats/src/header.rs
}

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

@caspervonb caspervonb Aug 14, 2023

Copy link
Copy Markdown
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.

@nepalez nepalez force-pushed the specialize-parse-errors branch from ec2546c to ba6866d Compare September 22, 2023 12:52
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.
@nepalez nepalez force-pushed the specialize-parse-errors branch from ba6866d to d46d8d4 Compare September 29, 2023 12:24
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.

2 participants