Skip to content

Conversation

link2xt
Copy link
Contributor

@link2xt link2xt commented Jul 21, 2025

I have looked through the code
to make sure errors are not ignored,
especially in loops.
Ignoring errors in loops
when reading from streams
may result in infinite loop
reading the same error over and over again.
No bugs found,
but I refactored reading from streams
to use try_next() more
to bubble up the errors with ?
as soon as possible.

This is a breaking change since
read_response() is resultified to return Result<Option<_>> instead of Option<Result<_>>.
read_response() is a public interface
that is used by library users
to read the banner.

I have looked through the code
to make sure errors are not ignored,
especially in loops.
Ignoring errors in loops
when reading from streams
may result in infinite loop
reading the same error over and over again.
No bugs found,
but I refactored reading from streams
to use `try_next()` more
to bubble up the errors with `?`
as soon as possible.

This is a breaking change since
`read_response()` is resultified to return `Result<Option<_>>`
instead of `Option<Result<_>>`.
`read_response()` is a public interface
that is used by library users
to read the banner.
Copy link
Contributor

@Hocuri Hocuri left a comment

Choose a reason for hiding this comment

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

I don't know this code, but I carefully read through the changes, and they look good as far as I can tell.

FTR, this PR is needed to protect against possible infinite loops like chatmail/core#6477. To quote @link2xt:

On error, repeated calls to next() return
Some(Err(_)), and if you are looking for None,
you may get stuck in infinite loop.

@link2xt link2xt merged commit 754eff8 into main Jul 21, 2025
22 checks passed
@link2xt link2xt deleted the link2xt/try-next branch July 21, 2025 14:00
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