Skip to content

Commit

Permalink
Replace os.IsNotExist(err) with errors.Is(err, fs.ErrNotExist) (#396
Browse files Browse the repository at this point in the history
)
  • Loading branch information
roger2hk authored Dec 9, 2024
1 parent afd61ea commit 6106156
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 3 additions & 1 deletion cmd/conformance/mysql/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ package main
import (
"context"
"database/sql"
"errors"
"flag"
"fmt"
"io"
"io/fs"
"net/http"
"os"
"time"
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion storage/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"database/sql"
"errors"
"fmt"
"io/fs"
"os"
"strings"
"time"
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 5 additions & 3 deletions storage/mysql/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ import (
"context"
"crypto/sha256"
"database/sql"
"errors"
"flag"
"fmt"
"io/fs"
"os"
"testing"
"time"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 6106156

Please sign in to comment.