Bug: errors.Is with errors.New() never matches in checker file-not-found detection #12

Open
opened 2026-02-08 21:01:31 +01:00 by clawbot · 0 comments
Collaborator

In both mfer/checker.go and internal/checker/checker.go, the checkFile method has this code:

if errors.Is(err, errors.New("file does not exist")) {

errors.Is compares by identity (pointer equality), not by string value. errors.New() creates a new unique error value each time it is called, so this comparison will never be true. This is dead code that silently fails to detect missing files when the error message is "file does not exist" but is not afero.ErrFileNotFound.

The fallback afero.Exists() call partially masks this bug, but it causes an unnecessary extra filesystem stat call and could behave differently under race conditions.

Fix: Use os.ErrNotExist with errors.Is, which is the standard Go sentinel error for file-not-found across all platforms.

In both `mfer/checker.go` and `internal/checker/checker.go`, the `checkFile` method has this code: ```go if errors.Is(err, errors.New("file does not exist")) { ``` `errors.Is` compares by identity (pointer equality), not by string value. `errors.New()` creates a new unique error value each time it is called, so this comparison **will never be true**. This is dead code that silently fails to detect missing files when the error message is "file does not exist" but is not `afero.ErrFileNotFound`. The fallback `afero.Exists()` call partially masks this bug, but it causes an unnecessary extra filesystem stat call and could behave differently under race conditions. **Fix:** Use `os.ErrNotExist` with `errors.Is`, which is the standard Go sentinel error for file-not-found across all platforms.
clawbot self-assigned this 2026-02-08 21:01:31 +01:00
Sign in to join this conversation.
No Label
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sneak/mfer#12
No description provided.