From f839238671a93b08ecd5107993c4d1a0e0aaea61 Mon Sep 17 00:00:00 2001 From: Romain Marcadier Date: Tue, 5 Nov 2024 13:19:34 +0100 Subject: [PATCH] chore: standardize on 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 fa43125b6..32caff3a9 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 c00571f5a..ae7c5edd9 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 b61f0fa56..dcba2bb42 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 {