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

Concrete error types for Core NATS #632

Merged
merged 30 commits into from
Mar 9, 2023
Merged

Concrete error types for Core NATS #632

merged 30 commits into from
Mar 9, 2023

Conversation

Jarema
Copy link
Member

@Jarema Jarema commented Sep 8, 2022

This PR experiments with concrete error types.

Feel free to share ideas and feedback.

@Jarema Jarema requested a review from caspervonb November 14, 2022 12:03
@Jarema Jarema changed the title [WIP] concrete error types Concrete error types for Core NATS Nov 14, 2022
#[error("request timed out")]
TimedOut,
#[error("no responders")]
NoResponders,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm still in favor of having something like Status(StatusCode) for status errors.

Copy link
Member Author

Choose a reason for hiding this comment

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

That could work but it will not, becase there are 5 or more different errors with status 408 and 409.

}

#[derive(Debug, Error)]
pub enum IoErrorKind {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure about the cases in this one just yet

Copy link
Member Author

Choose a reason for hiding this comment

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

Neither I'am.
Looking for better alternative over the weekend.

@caspervonb
Copy link
Collaborator

caspervonb commented Dec 19, 2022

Lots of conflicts now, want to split out Publish and Request errors and land them in the into_future branch?

Signed-off-by: Tomasz Pietrek <tomasz@nats.io>
Signed-off-by: Tomasz Pietrek <tomasz@nats.io>
Signed-off-by: Tomasz Pietrek <tomasz@nats.io>
Signed-off-by: Tomasz Pietrek <tomasz@nats.io>
Signed-off-by: Tomasz Pietrek <tomasz@nats.io>
// FIXME: we cant do PartialOrd, because mpsc errors are not PartialOrd
match err {
Err(RequestError::TimedOut) => {}
match err.kind() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm a fan

Copy link
Collaborator

@caspervonb caspervonb left a comment

Choose a reason for hiding this comment

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

Minor test nits

.await
.unwrap_err();
// FIXME: we cant do PartialOrd, because mpsc errors are not PartialOrd
match err.kind() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can do an assert(matches! instead here

.unwrap_err();
.unwrap_err()
.kind();
assert_eq!(RequestErrorKind::NoResponders, err);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Keep the err as the RequestError and dig into the field at assert time.

Suggested change
assert_eq!(RequestErrorKind::NoResponders, err);
assert_eq!(RequestErrorKind::NoResponders, err.kind());

tokio::time::Duration::from_millis(300),
client.request("test".into(), "request".into()),
)
.await
.unwrap()
.unwrap_err();
.unwrap_err()
.kind();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
.kind();

Signed-off-by: Tomasz Pietrek <tomasz@nats.io>
Jarema added 2 commits March 6, 2023 22:21
Signed-off-by: Tomasz Pietrek <tomasz@nats.io>
Signed-off-by: Tomasz Pietrek <tomasz@nats.io>
@Jarema Jarema force-pushed the jarema/concrete-errors branch from 2442cc1 to 02e8959 Compare March 6, 2023 21:41
Signed-off-by: Tomasz Pietrek <tomasz@nats.io>
}

impl FlushError {
fn with_source<E>(kind: FlushErrorKind, source: E) -> FlushError
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know this was my naming from slack but since its the only one.. new? 😁

Suggested change
fn with_source<E>(kind: FlushErrorKind, source: E) -> FlushError
fn new<E>(kind: FlushErrorKind, source: E) -> FlushError

From FlushErrorKind without a source would just be a blanket From implementation, which you already have.

Copy link
Member Author

Choose a reason for hiding this comment

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

In this case, yes, but for other Kind types we will need both methods - with and without source, and From would not always fit.

I would prefer to be consistent and have the naming the same across all errors.

Signed-off-by: Tomasz Pietrek <tomasz@nats.io>
@caspervonb caspervonb self-requested a review March 8, 2023 21:07
@Jarema Jarema marked this pull request as ready for review March 9, 2023 08:28
Signed-off-by: Tomasz Pietrek <tomasz@nats.io>
@Jarema Jarema force-pushed the jarema/concrete-errors branch from 258a2ba to 05fe32b Compare March 9, 2023 12:34
Copy link
Collaborator

@caspervonb caspervonb left a comment

Choose a reason for hiding this comment

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

lgtm

@Jarema Jarema merged commit f881df7 into main Mar 9, 2023
@Jarema Jarema deleted the jarema/concrete-errors branch March 9, 2023 15:57
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