fd icon indicating copy to clipboard operation
fd copied to clipboard

Panic when using `--full-path` if current working directory is invalid or removed

Open dataCenter430 opened this issue 8 months ago • 2 comments

Description

When --full-path (or -f) is used, fd builds absolute paths for each match. If the process’s current working directory becomes invalid during the search (e.g. it was deleted or permissions changed), the program can panic instead of reporting an error.

Location: src/walk.rs, in the worker closure that builds search_str for full-path matching (around lines 521–524).

Cause: filesystem::path_absolute_form(entry_path) can return an Err (for example when env::current_dir() fails). The code uses .expect("Retrieving absolute path succeeds"), which turns that error into a panic.

Reproduction (conceptually):

  1. Start fd with --full-path in a directory.
  2. From another process/shell, remove or make the current directory inaccessible (e.g. rmdir the CWD or revoke access) while the search is running.
  3. When fd tries to resolve a relative path, path_absolute_form fails and the process panics.

Suggested fix: Do not use .expect(). Either propagate the error (e.g. with ?) so the search can fail gracefully, or send a WorkerResult::Error and continue, so the user gets an error message and a non-zero exit code instead of a panic.

dataCenter430 avatar Mar 06 '26 00:03 dataCenter430

Hi, @tmccombs are you able to check this issue? If needed, I'd love to work on this. thx

dataCenter430 avatar Mar 06 '26 00:03 dataCenter430

Taking a look at this. @dataCenter430, if you're already working on a fix, let me know and I'll step back.

Xavrir avatar Mar 09 '26 17:03 Xavrir