fix(shmigrate): use errors.Is for fs.ErrNotExist compatibility

os.IsNotExist does not recognize fs.ErrNotExist when wrapped by an
fs.FS implementation. Switch to errors.Is(err, fs.ErrNotExist) so
the "file not found" check works for both os.Open and fs.FS.Open.
This commit is contained in:
AJ ONeal 2026-04-08 17:52:53 -06:00
parent 55298ac018
commit 9c672a9d76
No known key found for this signature in database
3 changed files with 5 additions and 4 deletions

View File

@ -2,6 +2,4 @@ module github.com/therootcompany/golib/database/sqlmigrate/shmigrate
go 1.26.1
require github.com/therootcompany/golib/database/sqlmigrate v0.0.0
replace github.com/therootcompany/golib/database/sqlmigrate => ../
require github.com/therootcompany/golib/database/sqlmigrate v1.0.0

View File

@ -0,0 +1,2 @@
github.com/therootcompany/golib/database/sqlmigrate v1.0.0 h1:vehFGUBdv/su0jDzSNxYN7N7i1KE3l2QJDf4x9LXhwQ=
github.com/therootcompany/golib/database/sqlmigrate v1.0.0/go.mod h1:7PQUjwT78Hx+SftcIKI2PH4zSFlrSO0V9h618PJqC38=

View File

@ -6,6 +6,7 @@ package shmigrate
import (
"bufio"
"context"
"errors"
"fmt"
"io"
"io/fs"
@ -103,7 +104,7 @@ func (r *Migrator) Applied(ctx context.Context) ([]sqlmigrate.AppliedMigration,
f, err = os.Open(r.LogPath)
}
if err != nil {
if os.IsNotExist(err) {
if errors.Is(err, fs.ErrNotExist) {
return nil, nil
}
return nil, fmt.Errorf("reading migrations log: %w", err)