Skip to content

refactor!: replace panics with errors across library and CLI - #166

Merged
veeso merged 1 commit into
mainfrom
refactor/remove-panic-from-code
Jun 29, 2026
Merged

refactor!: replace panics with errors across library and CLI#166
veeso merged 1 commit into
mainfrom
refactor/remove-panic-from-code

Conversation

@veeso

@veeso veeso commented Jun 29, 2026

Copy link
Copy Markdown
Owner

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

  • I have read the AI Policy and the contributing guidelines.
  • I have added rustdoc documentation for any new public API.
  • I have added tests covering my changes.
  • just check_code passes locally.
  • My commits follow the Conventional Commits format (the CHANGELOG.md is 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.

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
veeso force-pushed the refactor/remove-panic-from-code branch from c86c97c to 1c5f49b Compare June 29, 2026 10:54
@cocogitto-bot

cocogitto-bot Bot commented Jun 29, 2026

Copy link
Copy Markdown

✔️ 1c5f49b - Conventional commits check succeeded.

@veeso
veeso merged commit 27988d4 into main Jun 29, 2026
65 of 66 checks passed
@veeso
veeso deleted the refactor/remove-panic-from-code branch June 29, 2026 11:04
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.

1 participant