Skip to content

Report a file passed as the root instead of crashing [patch] - #166

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/file-path-as-root
Oct 6, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/file-path-as-root

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #162

What changed

FileScanner.ScanForFiles guarded with path.Exists. That is also true for a regular file, so the file path reached Directory.EnumerateFiles, which threw an unhandled DirectoryNotFoundException. All four verbs crashed with a stack trace.

The guard now checks two things:

  • File.Exists: prints Not a directory: <path> and returns an empty list.
  • Directory.Exists: keeps the existing Directory not found: <path> message.

The exit code is still 0. That is tracked separately in #144.

Tests

  • FileScannerAndHasherTests.ScanOfAFileReturnsNothing: ScanForFiles given a file path returns an empty list and does not throw.
  • VerbOutputTests.EveryVerbReportsAFilePathAsNotADirectory: Scan, DryRun, Stats and Deduplicate (answered y) each print the one-line error, and the file is left in place.

With the FileScanner.cs change reverted, both tests fail with the original exception. With it, the full suite passes: 61 passed, 2 pre-existing skips. I also ran the built dll against a file path and got the one-line error with no stack trace.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Q5ZFyLG9PgeKn5RpzhWEUQ


Generated by Claude Code

FileScanner.ScanForFiles guarded with path.Exists, which is also true
for a file, so Directory.EnumerateFiles threw an unhandled
DirectoryNotFoundException from every verb. A file path now prints
"Not a directory: ..." and the scan returns nothing, as a missing
directory already did.

Fixes #162

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q5ZFyLG9PgeKn5RpzhWEUQ
@sonarqubecloud

sonarqubecloud Bot commented Oct 6, 2026

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 030cfda into main Oct 6, 2026
14 checks passed
@matt-edmondson
matt-edmondson deleted the fix/file-path-as-root branch October 6, 2026 12:33
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.

Passing a file instead of a directory as -p crashes every verb with an unhandled DirectoryNotFoundException

2 participants