-
Notifications
You must be signed in to change notification settings - Fork 1
fix(NATSRS-001): CU-86akbh48z 3 review findings across 2 files #116
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,6 +111,34 @@ impl Display for StreamMessageErrorKind { | |
| } | ||
| } | ||
|
|
||
| /// The kinds of errors that can occur while performing a [Message::double_ack] or | ||
| /// [Acker::double_ack]. | ||
| #[derive(Debug, Clone, PartialEq)] | ||
| pub enum DoubleAckErrorKind { | ||
| /// The message is not a JetStream message (no reply subject). | ||
| NotJetStreamMessage, | ||
| /// The double ack response timed out. | ||
| DoubleAckTimeout, | ||
| /// The subscription used to await the double ack response was dropped | ||
| /// before a response was received. | ||
| SubscriptionDropped, | ||
| } | ||
|
|
||
| /// Error returned when a [Message::double_ack] or [Acker::double_ack] call fails. | ||
| pub type DoubleAckError = error::Error<DoubleAckErrorKind>; | ||
|
|
||
| impl Display for DoubleAckErrorKind { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| match self { | ||
| DoubleAckErrorKind::NotJetStreamMessage => { | ||
| write!(f, "no reply subject, not a JetStream message") | ||
| } | ||
| DoubleAckErrorKind::DoubleAckTimeout => write!(f, "double ack response timed out"), | ||
| DoubleAckErrorKind::SubscriptionDropped => write!(f, "subscription dropped"), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl std::ops::Deref for Message { | ||
| type Target = crate::Message; | ||
|
|
||
|
|
@@ -264,17 +292,16 @@ impl Message { | |
| match tokio::time::timeout(self.context.timeout, subscription.next()) | ||
| .await | ||
| .map_err(|_| { | ||
| std::io::Error::new( | ||
| std::io::ErrorKind::TimedOut, | ||
| "double ack response timed out", | ||
| ) | ||
| DoubleAckError::new(DoubleAckErrorKind::DoubleAckTimeout) | ||
| })? { | ||
| Some(_) => Ok(()), | ||
| None => Err(Box::new(std::io::Error::other("subscription dropped"))), | ||
| None => Err(Box::new(DoubleAckError::new( | ||
| DoubleAckErrorKind::SubscriptionDropped, | ||
| ))), | ||
| } | ||
| } else { | ||
| Err(Box::new(std::io::Error::other( | ||
| "No reply subject, not a JetStream message", | ||
| Err(Box::new(DoubleAckError::new( | ||
| DoubleAckErrorKind::NotJetStreamMessage, | ||
| ))) | ||
| } | ||
| } | ||
|
|
@@ -367,7 +394,7 @@ impl Message { | |
| OffsetDateTime::from_unix_timestamp_nanos(nanos)? | ||
| }, | ||
| pending: try_parse!(), | ||
| token: if n_tokens >= 9 { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 𦩠π info() token parsing uses n_tokens >= 9 branch even for exactly 9-token replies, but nested 'token' check duplicates same condition redundantly In π€ Prompt for AI agentsfix confidence: π‘ 80 medium β react π/π to teach the reviewer |
||
| token: if n_tokens > 9 { | ||
| Some(try_parse!(str)) | ||
| } else { | ||
| None | ||
|
|
@@ -553,17 +580,16 @@ impl Acker { | |
| match tokio::time::timeout(self.context.timeout, subscription.next()) | ||
| .await | ||
| .map_err(|_| { | ||
| std::io::Error::new( | ||
| std::io::ErrorKind::TimedOut, | ||
| "double ack response timed out", | ||
| ) | ||
| DoubleAckError::new(DoubleAckErrorKind::DoubleAckTimeout) | ||
| })? { | ||
| Some(_) => Ok(()), | ||
| None => Err(Box::new(std::io::Error::other("subscription dropped"))), | ||
| None => Err(Box::new(DoubleAckError::new( | ||
| DoubleAckErrorKind::SubscriptionDropped, | ||
| ))), | ||
| } | ||
| } else { | ||
| Err(Box::new(std::io::Error::other( | ||
| "No reply subject, not a JetStream message", | ||
| Err(Box::new(DoubleAckError::new( | ||
| DoubleAckErrorKind::NotJetStreamMessage, | ||
| ))) | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,15 +15,31 @@ use std::fmt::Display; | |
|
|
||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| impl std::error::Error for Error {} | ||
| /// Error kind describing a service request error payload. | ||
| #[derive(Debug, Clone, PartialEq)] | ||
| pub enum ErrorKind { | ||
| /// The service returned an error response with the given status and code. | ||
| Request, | ||
| } | ||
|
|
||
| impl Display for ErrorKind { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| match self { | ||
| ErrorKind::Request => write!(f, "service request error"), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Error returned when a service request fails. | ||
| pub type Error = crate::error::Error<ErrorKind>; | ||
|
|
||
| #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 𦩠π΄ service::error::Error is an ad-hoc public error struct, not the crate's Error/ErrorKind pattern In π€ Prompt for AI agentsfix confidence: π΄ 35 low β review closely β react π/π to teach the reviewer |
||
| pub struct Error { | ||
| pub struct ErrorPayload { | ||
| pub status: String, | ||
| pub code: usize, | ||
| } | ||
|
|
||
| impl Display for Error { | ||
| impl Display for ErrorPayload { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| write!( | ||
| f, | ||
|
|
@@ -32,3 +48,11 @@ impl Display for Error { | |
| ) | ||
| } | ||
| } | ||
|
|
||
| impl std::error::Error for ErrorPayload {} | ||
|
|
||
| impl From<ErrorPayload> for Error { | ||
| fn from(payload: ErrorPayload) -> Self { | ||
| Error::with_source(ErrorKind::Request, payload.to_string(), payload) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
𦩠π *double_ack() uses raw io::Error for timeout/dropped-subscription failures instead of a typed ErrorKind
In
Message::double_ackandAcker::double_ack(both instances), replaced the rawstd::io::Errorvariants with a new typed errorDoubleAckError/DoubleAckErrorKind(added near the top of the file, alongsideStreamMessageErrorKind). The timeout case now maps toDoubleAckErrorKind::DoubleAckTimeout, the dropped-subscription case maps toDoubleAckErrorKind::SubscriptionDropped, and the "no reply subject" case in bothdouble_ackmethods maps toDoubleAckErrorKind::NotJetStreamMessage. This follows the sameerror::Error<Kind>pattern already used byStreamMessageErrorin this file. Risk: this is a public API-shape change (new exported typesDoubleAckErrorKind/DoubleAckError); existing callers matching onio::ErrorKindvia downcast will break, but that is the intended fix per the finding. I did not change the unrelatedack()/ack_with()"no reply subject" io::Error paths since the finding only concernsdouble_ack().π€ Prompt for AI agents
fix confidence: π‘ 70 medium β react π/π to teach the reviewer