Bug: errors.Is with errors.New() never matches in checker file-not-found detection #12
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
In both
mfer/checker.goandinternal/checker/checker.go, thecheckFilemethod has this code:errors.Iscompares 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 notafero.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.ErrNotExistwitherrors.Is, which is the standard Go sentinel error for file-not-found across all platforms.