From 61061560bcf255ebc9b14283d8a357f61f3d418a Mon Sep 17 00:00:00 2001 From: Roger Ng Date: Mon, 9 Dec 2024 09:52:49 +0000 Subject: [PATCH] Replace `os.IsNotExist(err)` with `errors.Is(err, fs.ErrNotExist)` (#396) --- cmd/conformance/mysql/main.go | 4 +++- storage/mysql/mysql.go | 3 ++- storage/mysql/mysql_test.go | 8 +++++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/cmd/conformance/mysql/main.go b/cmd/conformance/mysql/main.go index 2fe58d08..d8f7a4c6 100644 --- a/cmd/conformance/mysql/main.go +++ b/cmd/conformance/mysql/main.go @@ -18,9 +18,11 @@ package main import ( "context" "database/sql" + "errors" "flag" "fmt" "io" + "io/fs" "net/http" "os" "time" @@ -168,7 +170,7 @@ func configureTilesReadAPI(mux *http.ServeMux, storage *mysql.Storage) { inferredMinTreeSize := (index*256 + width) << (level * 8) tile, err := storage.ReadTile(r.Context(), level, index, inferredMinTreeSize) if err != nil { - if os.IsNotExist(err) { + if errors.Is(err, fs.ErrNotExist) { w.WriteHeader(http.StatusNotFound) return } diff --git a/storage/mysql/mysql.go b/storage/mysql/mysql.go index a6d62dd2..8ac67862 100644 --- a/storage/mysql/mysql.go +++ b/storage/mysql/mysql.go @@ -22,6 +22,7 @@ import ( "database/sql" "errors" "fmt" + "io/fs" "os" "strings" "time" @@ -123,7 +124,7 @@ func (s *Storage) maybeInitTree(ctx context.Context) error { }() treeState, err := s.readTreeState(ctx, tx) - if err != nil && !os.IsNotExist(err) { + if err != nil && !errors.Is(err, fs.ErrNotExist) { klog.Errorf("Failed to read tree state: %v", err) return err } diff --git a/storage/mysql/mysql_test.go b/storage/mysql/mysql_test.go index d84d733e..a9da561c 100644 --- a/storage/mysql/mysql_test.go +++ b/storage/mysql/mysql_test.go @@ -24,8 +24,10 @@ import ( "context" "crypto/sha256" "database/sql" + "errors" "flag" "fmt" + "io/fs" "os" "testing" "time" @@ -238,7 +240,7 @@ func TestGetTile(t *testing.T) { t.Run(test.name, func(t *testing.T) { tile, err := s.ReadTile(ctx, test.level, test.index, test.treeSize) if err != nil { - if notFound, wantNotFound := os.IsNotExist(err), test.wantNotFound; notFound != wantNotFound { + if notFound, wantNotFound := errors.Is(err, fs.ErrNotExist), test.wantNotFound; notFound != wantNotFound { t.Errorf("wantNotFound %v but notFound %v", wantNotFound, notFound) } if test.wantNotFound { @@ -274,7 +276,7 @@ func TestReadMissingTile(t *testing.T) { t.Run(test.name, func(t *testing.T) { tile, err := s.ReadTile(ctx, test.level, test.index, test.width) if err != nil { - if os.IsNotExist(err) { + if errors.Is(err, fs.ErrNotExist) { // this is success for this test return } @@ -307,7 +309,7 @@ func TestReadMissingEntryBundle(t *testing.T) { t.Run(test.name, func(t *testing.T) { entryBundle, err := s.ReadEntryBundle(ctx, test.index, test.index) if err != nil { - if os.IsNotExist(err) { + if errors.Is(err, fs.ErrNotExist) { // this is success for this test return }