Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Remove some references to pkg/errors #5270

Merged
merged 6 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions server/core/config/parser_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"os"
Expand All @@ -11,7 +12,7 @@ import (

validation "github.com/go-ozzo/ozzo-validation"
shlex "github.com/google/shlex"
"github.com/pkg/errors"

"github.com/runatlantis/atlantis/server/core/config/raw"
"github.com/runatlantis/atlantis/server/core/config/valid"
yaml "gopkg.in/yaml.v3"
Expand All @@ -29,11 +30,11 @@ func (p *ParserValidator) HasRepoCfg(absRepoDir, repoConfigFile string) (bool, e
const invalidExtensionFilename = "atlantis.yml"
_, err := os.Stat(p.repoCfgPath(absRepoDir, invalidExtensionFilename))
if err == nil {
return false, errors.Errorf("found %q as config file; rename using the .yaml extension", invalidExtensionFilename)
return false, fmt.Errorf("found %q as config file; rename using the .yaml extension", invalidExtensionFilename)
}

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

if err != nil {
if !os.IsNotExist(err) {
return valid.RepoCfg{}, errors.Wrapf(err, "unable to read %s file", repoConfigFile)
}
// Don't wrap os.IsNotExist errors because we want our callers to be
// able to detect if it's a NotExist err.
return valid.RepoCfg{}, err
return valid.RepoCfg{}, fmt.Errorf("unable to read %s file: %w", repoConfigFile, err)
}
return p.ParseRepoCfgData(configData, globalCfg, repoID, branch)
}
Expand Down Expand Up @@ -115,7 +111,7 @@ func (p *ParserValidator) ParseRepoCfgData(repoCfgData []byte, globalCfg valid.G
func (p *ParserValidator) ParseGlobalCfg(configFile string, defaultCfg valid.GlobalCfg) (valid.GlobalCfg, error) {
configData, err := os.ReadFile(configFile) // nolint: gosec
if err != nil {
return valid.GlobalCfg{}, errors.Wrapf(err, "unable to read %s file", configFile)
return valid.GlobalCfg{}, fmt.Errorf("unable to read %s file: %w", configFile, err)
}
if len(configData) == 0 {
return valid.GlobalCfg{}, fmt.Errorf("file %s was empty", configFile)
Expand Down Expand Up @@ -204,7 +200,7 @@ func (p *ParserValidator) applyLegacyShellParsing(cfg *valid.RepoCfg) error {
if s.StepName == "run" {
split, err := shlex.Split(s.RunCommand)
if err != nil {
return errors.Wrapf(err, "unable to parse %q", s.RunCommand)
return fmt.Errorf("unable to parse %q: %w", s.RunCommand, err)
}
s.RunCommand = strings.Join(split, " ")
}
Expand Down
6 changes: 4 additions & 2 deletions server/core/config/parser_validator_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package config_test

import (
"errors"
"fmt"
"io/fs"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -50,14 +52,14 @@ func TestHasRepoCfg_InvalidFileExtension(t *testing.T) {
func TestParseRepoCfg_DirDoesNotExist(t *testing.T) {
r := config.ParserValidator{}
_, err := r.ParseRepoCfg("/not/exist", globalCfg, "", "")
Assert(t, os.IsNotExist(err), "exp not exist err")
Assert(t, errors.Is(err, fs.ErrNotExist), "exp not exist err")
}

func TestParseRepoCfg_FileDoesNotExist(t *testing.T) {
tmpDir := t.TempDir()
r := config.ParserValidator{}
_, err := r.ParseRepoCfg(tmpDir, globalCfg, "", "")
Assert(t, os.IsNotExist(err), "exp not exist err")
Assert(t, errors.Is(err, fs.ErrNotExist), "exp not exist err")
}

func TestParseRepoCfg_BadPermissions(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion server/core/config/raw/autodiscover.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package raw

import (
"errors"
"fmt"
"strings"

"github.com/bmatcuk/doublestar/v4"
validation "github.com/go-ozzo/ozzo-validation"
"github.com/pkg/errors"
"github.com/runatlantis/atlantis/server/core/config/valid"
)

Expand Down
12 changes: 9 additions & 3 deletions server/core/config/raw/global_cfg.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package raw

import (
"errors"
"fmt"
"regexp"
"strings"

validation "github.com/go-ozzo/ozzo-validation"
"github.com/pkg/errors"
"github.com/runatlantis/atlantis/server/core/config/valid"
"github.com/runatlantis/atlantis/server/utils"
)
Expand Down Expand Up @@ -184,7 +184,10 @@ func (r Repo) Validate() error {
return nil
}
_, err := regexp.Compile(id[1 : len(id)-1])
return errors.Wrapf(err, "parsing: %s", id)
if err != nil {
return fmt.Errorf("parsing: %s: %w", id, err)
}
return nil
}

branchValid := func(value interface{}) error {
Expand All @@ -197,7 +200,10 @@ func (r Repo) Validate() error {
}
withoutSlashes := branch[1 : len(branch)-1]
_, err := regexp.Compile(withoutSlashes)
return errors.Wrapf(err, "parsing: %s", branch)
if err != nil {
return fmt.Errorf("parsing: %s: %w", branch, err)
}
return nil
}

repoConfigFileValid := func(value interface{}) error {
Expand Down
7 changes: 5 additions & 2 deletions server/core/config/raw/project.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package raw

import (
"errors"
"fmt"
"net/url"
"path/filepath"
Expand All @@ -9,7 +10,6 @@ import (

validation "github.com/go-ozzo/ozzo-validation"
version "github.com/hashicorp/go-version"
"github.com/pkg/errors"
"github.com/runatlantis/atlantis/server/core/config/valid"
)

Expand Down Expand Up @@ -75,7 +75,10 @@ func (p Project) Validate() error {
}
withoutSlashes := branch[1 : len(branch)-1]
_, err := regexp.Compile(withoutSlashes)
return errors.Wrapf(err, "parsing: %s", branch)
if err != nil {
return fmt.Errorf("parsing: %s: %w", branch, err)
}
return nil
}

DependsOn := func(value interface{}) error {
Expand Down
8 changes: 6 additions & 2 deletions server/core/config/raw/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
package raw

import (
"fmt"

version "github.com/hashicorp/go-version"
"github.com/pkg/errors"
)

// VersionValidator helper function to validate binary version.
Expand All @@ -16,5 +17,8 @@ func VersionValidator(value interface{}) error {
return nil
}
_, err := version.NewVersion(*strPtr)
return errors.Wrapf(err, "version %q could not be parsed", *strPtr)
if err != nil {
return fmt.Errorf("version %q could not be parsed: %w", *strPtr, err)
}
return nil
}
3 changes: 2 additions & 1 deletion server/core/config/raw/raw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import (
"io"
"strings"

"github.com/pkg/errors"
"errors"

"gopkg.in/yaml.v3"
)

Expand Down
Loading