Skip to content

Pin the exceptions thrown for null, malformed and missing table paths - #343

Merged
chrisrichards merged 1 commit into
mainfrom
pin-invalid-path-exceptions
Nov 23, 2026
Merged

chrisrichards merged 1 commit into
mainfrom
pin-invalid-path-exceptions

Conversation

@chrisrichards

Copy link
Copy Markdown
Member

Why

#342 resolves the table path with Path.GetFullPath before checking that the file exists. Path.GetFullPath throws for inputs where File.Exists only returned false, so the exception for an unusable path changed without being called out in that pull request:

Path passed to DbfTable / DbfDataReader Before #342 Now
null FileNotFoundException ArgumentNullException (ParamName is path)
"" FileNotFoundException ArgumentException
Contains a NUL character FileNotFoundException ArgumentException
File does not exist FileNotFoundException FileNotFoundException

The new exceptions are the ones File.OpenRead and FileStream throw for the same inputs, and they describe the problem better than "file not found" does for a null path. This pull request keeps them and makes them intentional.

Changes

Tests only: three tests in DbfTableTests state the exception for each case above. No library code changes.

Compatibility

Code that catches FileNotFoundException to handle a null or empty path will now see an argument exception instead. This will go in the compatibility notes for v2.3.2.

Testing

dotnet test -c Release: 539 passed, 1 skipped (already skipped on main).

🤖 Generated with Claude Code

Since #342 the table path is resolved with Path.GetFullPath before the
existence check, so a null path throws ArgumentNullException and an
empty path or one containing a NUL character throws ArgumentException.
Previously all three were reported as FileNotFoundException. The new
exceptions match File.OpenRead and FileStream and describe the problem
better, so the tests now state them as the intended behaviour. A path
to a file that does not exist still throws FileNotFoundException.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@chrisrichards
chrisrichards merged commit 583fe9c into main Nov 23, 2026
3 checks passed
@chrisrichards
chrisrichards deleted the pin-invalid-path-exceptions branch November 23, 2026 15:03
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