From 28c50eb4f65654a96c4c1536dde4c978206b308b Mon Sep 17 00:00:00 2001 From: Romain Marcadier Date: Fri, 8 Nov 2024 11:43:45 +0100 Subject: [PATCH] chore: standardize on `errors.Is(err, fs.ErrNotExist)` (#379) The documentation for `os.IsNotExist` states: > This function predates [errors.Is](https://pkg.go.dev/errors#Is). It only supports errors returned by the os package. New code should use `errors.Is(err, fs.ErrNotExist)`. --- internal/pin/gomod.go | 4 +++- internal/pin/pin.go | 3 ++- main.go | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/pin/gomod.go b/internal/pin/gomod.go index fa43125b..32caff3a 100644 --- a/internal/pin/gomod.go +++ b/internal/pin/gomod.go @@ -8,8 +8,10 @@ package pin import ( "bytes" "encoding/json" + "errors" "fmt" "io" + "io/fs" "os" "os/exec" "path/filepath" @@ -105,7 +107,7 @@ func runGoModEdit(modfile string, edits ...goModEdit) error { vendorDir := filepath.Join(modfile, "..", "vendor") stat, err := os.Stat(vendorDir) - if os.IsNotExist(err) || (err == nil && !stat.IsDir()) { + if errors.Is(err, fs.ErrNotExist) || (err == nil && !stat.IsDir()) { // No `vendor` directory, nothing to do... return nil } diff --git a/internal/pin/pin.go b/internal/pin/pin.go index c00571f5..ae7c5edd 100644 --- a/internal/pin/pin.go +++ b/internal/pin/pin.go @@ -13,6 +13,7 @@ import ( "go/token" goversion "go/version" "io" + "io/fs" "os" "path/filepath" "strings" @@ -256,7 +257,7 @@ func pruneImports(importSet *importSet, opts Options) (bool, error) { } integrationsFile := filepath.Join(someFile, "..", orchestrionDotYML) if _, err := os.Stat(integrationsFile); err != nil { - if os.IsNotExist(err) { + if errors.Is(err, fs.ErrNotExist) { pruned = pruneImport(importSet, pkg.PkgPath, "there is no "+orchestrionDotYML+" file in this package", opts) || pruned continue } diff --git a/main.go b/main.go index b61f0fa5..dcba2bb4 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "errors" "fmt" "io" + "io/fs" "os" "path/filepath" "runtime/pprof" @@ -122,7 +123,7 @@ func main() { if err != nil { return err } - if err := os.MkdirAll(profilePath, 0775); err != nil && !os.IsExist(err) { + if err := os.MkdirAll(profilePath, 0775); err != nil && !errors.Is(err, fs.ErrExist) { return err } if err := os.Setenv(envVarOrchestrionProfilePath, profilePath); err != nil {