refactor!: replace panics with errors across library and CLI - #166
Merged
Conversation
Convert unwrap/expect/panic patterns in production code paths to proper FtpError/ParseError results, so malformed server responses (e.g. an out-of-range PASV octet or unparsable LIST/MLSx line) and socket-clone failures no longer abort the program. Placeholder no-TLS streams now return io errors or unreachable! for truly unreachable accessors. BREAKING CHANGE: the `tcp_stream` method of the `TlsStream`, `TokioTlsStream` and `SmolTlsStream` traits now returns `FtpResult<TcpStream>` instead of `TcpStream`, and `DataStream::into_tcp_stream` now returns `FtpResult<TcpStream>`.
veeso
force-pushed
the
refactor/remove-panic-from-code
branch
from
June 29, 2026 10:54
c86c97c to
1c5f49b
Compare
|
✔️ 1c5f49b - Conventional commits check succeeded. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The library used to crash in several places when something went wrong, using patterns that stop the whole program instead of reporting a recoverable error. This was unsafe for a library, because a single bad reply from a server or a failed socket operation could take down the application using it.
This change replaces those crash points with normal error results. The affected cases include parsing a passive mode reply with an out of range value, parsing malformed directory listing lines, recovering the plain connection from a secure one, and reading user input in the command line tool. In all of these the code now returns an error that the caller can handle, instead of aborting.
A few internal placeholder streams (used only for plain, non secure connections) keep a guard that signals a programming mistake if they are ever reached, since by design they never are.
Fixes #
Checklist
just check_codepasses locally.CHANGELOG.mdis generated from them at release time).AI Disclosure
This change was prepared with Claude Code. It located the crash points, applied the conversions to error results, and ran the build, lints, and tests. All changes were reviewed by the author.
Notes
This is a breaking change. The method that returns the underlying TCP connection now returns a result that can fail, both on the trait that abstracts TLS streams and on the public data stream type. Code that called these and expected a plain value will need to handle the error case. The version bump is intentionally left out and will be done at release time.