fix(NATSRS-002): CU-86akbhh82 info() constructs io::Error and Box<dyn Error> instead of the crate's Error<Kind> pattern - #135
flamingo[bot] wants to merge 1 commit into
Conversation
…ad of the crate's Error<Kind> pattern
| InfoError::new(InfoErrorKind::MissingReplySubject) | ||
| })?; | ||
|
|
||
| if !reply.starts_with(PREFIX) { |
There was a problem hiding this comment.
🦩 🔴 info() constructs io::Error and Box instead of the crate's Error pattern
Introduced a dedicated InfoErrorKind enum (MissingReplySubject, MissingPrefix, TooFewTokens, ParseError, BadTokenNumber) and its InfoError = error::Error<InfoErrorKind> type alias, following the same pattern as StreamMessageErrorKind/StreamMessageError defined earlier in the file. In Message::info() (async-nats/src/jetstream/message.rs), replaced all std::io::Error/Box::new(std::io::Error::other(...)) constructions with InfoError::new(...) / InfoError::with_source(...) for the missing-reply-subject check, missing-prefix check, the try_parse! macro's too-few-tokens and parse-error branches, and the final bad-token-number branch. The function signature Result<Info<'_>, Error> is unchanged since InfoError boxes into Error via the existing From impl used elsewhere in the crate (as seen with StreamMessageError usage patterns). Left the unrelated ack/ack_with/double_ack/Acker io::Error usages untouched since the finding only targeted info(). Risk: I could not see the exact error::Error::new/with_source signatures beyond their use with StreamMessageErrorKind, so I mirrored that call convention exactly; if Error::new requires different arity this won't compile, but the pattern used is identical to the one already proven in this same file.
🤖 Prompt for AI agents
In async-nats/src/jetstream/message.rs around line 293, review and complete this code-review fix: info() constructs io::Error and Box<dyn Error> instead of the crate's Error<Kind> pattern.
What the draft fix changed: Introduced a dedicated `InfoErrorKind` enum (MissingReplySubject, MissingPrefix, TooFewTokens, ParseError, BadTokenNumber) and its `InfoError = error::Error<InfoErrorKind>` type alias, following the same pattern as `StreamMessageErrorKind`/`StreamMessageError` defined earlier in the file. In `Message::info()` (async-nats/src/jetstream/message.rs), replaced all `std::io::Error`/`Box::new(std::io::Error::other(...))` constructions with `InfoError::new(...)` / `InfoError::with_source(...)` for the missing-reply-subject check, missing-prefix check, the `try_parse!` macro's too-few-tokens and parse-error branches, and the final bad-token-number branch. The function signature `Result<Info<'_>, Error>` is unchanged since `InfoError` boxes into `Error` via the existing `From` impl used elsewhere in the crate (as seen with `StreamMessageError` usage patterns). Left the unrelated `ack`/`ack_with`/`double_ack`/`Acker` io::Error usages untouched since the finding only targeted `info()`. Risk: I could not see the exact `error::Error::new`/`with_source` signatures beyond their use with `StreamMessageErrorKind`, so I mirrored that call convention exactly; if `Error::new` requires different arity this won't compile, but the pattern used is identical to the one already proven in this same file.
Verify the change is correct and complete; do not refactor unrelated code.
fix confidence: 🟡 75 medium — react 👍/👎 to teach the reviewer
Closes findings from rule NATSRS-002 — info() constructs io::Error and Box instead of the crate's Error pattern.
Draft — this is a starting point, not a finished change. The fix required judgment, so read it before trusting it.
async-nats/src/jetstream/message.rs:293What changed — and what was deliberately left — is explained per finding as inline review comments on the lines each finding touched.
Run: https://product-hub.flamingo.so/admin/code-review
Run id:
4fa2224e-8528-443d-a51a-823c78308977Merging this PR is recorded as acceptance of the rule that produced it;
closing it unmerged is recorded as rejection. Both feed rule health, so
closing a wrong suggestion is useful rather than merely tidy.
ClickUp task: CU-86akbhh82 NATS async-nats and CI review findings (9 PRs)