Skip to content

Commit

Permalink
chore: standardize on errors.Is(err, fs.ErrNotExist) (#379)
Browse files Browse the repository at this point in the history
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)`.
  • Loading branch information
RomainMuller authored Nov 8, 2024
1 parent 72eaa80 commit 28c50eb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion internal/pin/gomod.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ package pin
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"io/fs"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion internal/pin/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"go/token"
goversion "go/version"
"io"
"io/fs"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"errors"
"fmt"
"io"
"io/fs"
"os"
"path/filepath"
"runtime/pprof"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 28c50eb

Please sign in to comment.