Skip to content

Commit 03ea1a1

Browse files
authored
chore: Remove some references to pkg/errors (#5270)
Signed-off-by: Luke Massa <[email protected]>
1 parent 6bf6acf commit 03ea1a1

File tree

7 files changed

+34
-22
lines changed

7 files changed

+34
-22
lines changed

server/core/config/parser_validator.go

+7-11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package config
33
import (
44
"bytes"
55
"encoding/json"
6+
"errors"
67
"fmt"
78
"io"
89
"os"
@@ -11,7 +12,7 @@ import (
1112

1213
validation "github.com/go-ozzo/ozzo-validation"
1314
shlex "github.com/google/shlex"
14-
"github.com/pkg/errors"
15+
1516
"github.com/runatlantis/atlantis/server/core/config/raw"
1617
"github.com/runatlantis/atlantis/server/core/config/valid"
1718
yaml "gopkg.in/yaml.v3"
@@ -29,11 +30,11 @@ func (p *ParserValidator) HasRepoCfg(absRepoDir, repoConfigFile string) (bool, e
2930
const invalidExtensionFilename = "atlantis.yml"
3031
_, err := os.Stat(p.repoCfgPath(absRepoDir, invalidExtensionFilename))
3132
if err == nil {
32-
return false, errors.Errorf("found %q as config file; rename using the .yaml extension", invalidExtensionFilename)
33+
return false, fmt.Errorf("found %q as config file; rename using the .yaml extension", invalidExtensionFilename)
3334
}
3435

3536
_, err = os.Stat(p.repoCfgPath(absRepoDir, repoConfigFile))
36-
if os.IsNotExist(err) {
37+
if errors.Is(err, os.ErrNotExist) {
3738
return false, nil
3839
}
3940
return err == nil, err
@@ -48,12 +49,7 @@ func (p *ParserValidator) ParseRepoCfg(absRepoDir string, globalCfg valid.Global
4849
configData, err := os.ReadFile(configFile) // nolint: gosec
4950

5051
if err != nil {
51-
if !os.IsNotExist(err) {
52-
return valid.RepoCfg{}, errors.Wrapf(err, "unable to read %s file", repoConfigFile)
53-
}
54-
// Don't wrap os.IsNotExist errors because we want our callers to be
55-
// able to detect if it's a NotExist err.
56-
return valid.RepoCfg{}, err
52+
return valid.RepoCfg{}, fmt.Errorf("unable to read %s file: %w", repoConfigFile, err)
5753
}
5854
return p.ParseRepoCfgData(configData, globalCfg, repoID, branch)
5955
}
@@ -115,7 +111,7 @@ func (p *ParserValidator) ParseRepoCfgData(repoCfgData []byte, globalCfg valid.G
115111
func (p *ParserValidator) ParseGlobalCfg(configFile string, defaultCfg valid.GlobalCfg) (valid.GlobalCfg, error) {
116112
configData, err := os.ReadFile(configFile) // nolint: gosec
117113
if err != nil {
118-
return valid.GlobalCfg{}, errors.Wrapf(err, "unable to read %s file", configFile)
114+
return valid.GlobalCfg{}, fmt.Errorf("unable to read %s file: %w", configFile, err)
119115
}
120116
if len(configData) == 0 {
121117
return valid.GlobalCfg{}, fmt.Errorf("file %s was empty", configFile)
@@ -204,7 +200,7 @@ func (p *ParserValidator) applyLegacyShellParsing(cfg *valid.RepoCfg) error {
204200
if s.StepName == "run" {
205201
split, err := shlex.Split(s.RunCommand)
206202
if err != nil {
207-
return errors.Wrapf(err, "unable to parse %q", s.RunCommand)
203+
return fmt.Errorf("unable to parse %q: %w", s.RunCommand, err)
208204
}
209205
s.RunCommand = strings.Join(split, " ")
210206
}

server/core/config/parser_validator_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package config_test
22

33
import (
4+
"errors"
45
"fmt"
6+
"io/fs"
57
"os"
68
"path/filepath"
79
"regexp"
@@ -50,14 +52,14 @@ func TestHasRepoCfg_InvalidFileExtension(t *testing.T) {
5052
func TestParseRepoCfg_DirDoesNotExist(t *testing.T) {
5153
r := config.ParserValidator{}
5254
_, err := r.ParseRepoCfg("/not/exist", globalCfg, "", "")
53-
Assert(t, os.IsNotExist(err), "exp not exist err")
55+
Assert(t, errors.Is(err, fs.ErrNotExist), "exp not exist err")
5456
}
5557

5658
func TestParseRepoCfg_FileDoesNotExist(t *testing.T) {
5759
tmpDir := t.TempDir()
5860
r := config.ParserValidator{}
5961
_, err := r.ParseRepoCfg(tmpDir, globalCfg, "", "")
60-
Assert(t, os.IsNotExist(err), "exp not exist err")
62+
Assert(t, errors.Is(err, fs.ErrNotExist), "exp not exist err")
6163
}
6264

6365
func TestParseRepoCfg_BadPermissions(t *testing.T) {

server/core/config/raw/autodiscover.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package raw
22

33
import (
4+
"errors"
45
"fmt"
56
"strings"
67

78
"github.com/bmatcuk/doublestar/v4"
89
validation "github.com/go-ozzo/ozzo-validation"
9-
"github.com/pkg/errors"
1010
"github.com/runatlantis/atlantis/server/core/config/valid"
1111
)
1212

server/core/config/raw/global_cfg.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package raw
22

33
import (
4+
"errors"
45
"fmt"
56
"regexp"
67
"strings"
78

89
validation "github.com/go-ozzo/ozzo-validation"
9-
"github.com/pkg/errors"
1010
"github.com/runatlantis/atlantis/server/core/config/valid"
1111
"github.com/runatlantis/atlantis/server/utils"
1212
)
@@ -184,7 +184,10 @@ func (r Repo) Validate() error {
184184
return nil
185185
}
186186
_, err := regexp.Compile(id[1 : len(id)-1])
187-
return errors.Wrapf(err, "parsing: %s", id)
187+
if err != nil {
188+
return fmt.Errorf("parsing: %s: %w", id, err)
189+
}
190+
return nil
188191
}
189192

190193
branchValid := func(value interface{}) error {
@@ -197,7 +200,10 @@ func (r Repo) Validate() error {
197200
}
198201
withoutSlashes := branch[1 : len(branch)-1]
199202
_, err := regexp.Compile(withoutSlashes)
200-
return errors.Wrapf(err, "parsing: %s", branch)
203+
if err != nil {
204+
return fmt.Errorf("parsing: %s: %w", branch, err)
205+
}
206+
return nil
201207
}
202208

203209
repoConfigFileValid := func(value interface{}) error {

server/core/config/raw/project.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package raw
22

33
import (
4+
"errors"
45
"fmt"
56
"net/url"
67
"path/filepath"
@@ -9,7 +10,6 @@ import (
910

1011
validation "github.com/go-ozzo/ozzo-validation"
1112
version "github.com/hashicorp/go-version"
12-
"github.com/pkg/errors"
1313
"github.com/runatlantis/atlantis/server/core/config/valid"
1414
)
1515

@@ -75,7 +75,10 @@ func (p Project) Validate() error {
7575
}
7676
withoutSlashes := branch[1 : len(branch)-1]
7777
_, err := regexp.Compile(withoutSlashes)
78-
return errors.Wrapf(err, "parsing: %s", branch)
78+
if err != nil {
79+
return fmt.Errorf("parsing: %s: %w", branch, err)
80+
}
81+
return nil
7982
}
8083

8184
DependsOn := func(value interface{}) error {

server/core/config/raw/raw.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
package raw
55

66
import (
7+
"fmt"
8+
79
version "github.com/hashicorp/go-version"
8-
"github.com/pkg/errors"
910
)
1011

1112
// VersionValidator helper function to validate binary version.
@@ -16,5 +17,8 @@ func VersionValidator(value interface{}) error {
1617
return nil
1718
}
1819
_, err := version.NewVersion(*strPtr)
19-
return errors.Wrapf(err, "version %q could not be parsed", *strPtr)
20+
if err != nil {
21+
return fmt.Errorf("version %q could not be parsed: %w", *strPtr, err)
22+
}
23+
return nil
2024
}

server/core/config/raw/raw_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import (
44
"io"
55
"strings"
66

7-
"github.com/pkg/errors"
7+
"errors"
8+
89
"gopkg.in/yaml.v3"
910
)
1011

0 commit comments

Comments
 (0)