From f20ab7dea227efd4a3a367e353743a03400d9026 Mon Sep 17 00:00:00 2001 From: Grzegorz Dlugoszewski Date: Sun, 24 Aug 2025 16:53:48 +0200 Subject: [PATCH] Fix issues found by err113 linter --- pkg/get.go | 5 ++++- pkg/git/finder.go | 14 +++++++++----- pkg/git/finder_test.go | 12 +----------- pkg/list.go | 5 ++++- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/pkg/get.go b/pkg/get.go index e59f90b..6878ebb 100644 --- a/pkg/get.go +++ b/pkg/get.go @@ -1,11 +1,14 @@ package pkg import ( + "errors" "fmt" "git-get/pkg/git" "path/filepath" ) +var ErrMissingRepoArg = errors.New("missing argument or --dump flag") + // GetCfg provides configuration for the Get command. type GetCfg struct { Branch string @@ -20,7 +23,7 @@ type GetCfg struct { // Get executes the "git get" command. func Get(conf *GetCfg) error { if conf.URL == "" && conf.Dump == "" { - return fmt.Errorf("missing argument or --dump flag") + return ErrMissingRepoArg } if conf.URL != "" { diff --git a/pkg/git/finder.go b/pkg/git/finder.go index 374aea0..8926649 100644 --- a/pkg/git/finder.go +++ b/pkg/git/finder.go @@ -1,6 +1,7 @@ package git import ( + "errors" "fmt" "io/fs" "os" @@ -12,8 +13,11 @@ import ( // Max number of concurrently running status loading workers. const maxWorkers = 100 -var errDirNoAccess = fmt.Errorf("directory can't be accessed") -var errDirNotExist = fmt.Errorf("directory doesn't exist") +var ( + ErrDirNoAccess = errors.New("directory can't be accessed") + ErrDirNotExist = errors.New("directory doesn't exist") + ErrNoReposFound = errors.New("no git repositories found") +) // Exists returns true if a directory exists. If it doesn't or the directory can't be accessed it returns an error. func Exists(path string) (bool, error) { @@ -23,11 +27,11 @@ func Exists(path string) (bool, error) { } if os.IsNotExist(err) { - return false, fmt.Errorf("can't access %s: %w", path, errDirNotExist) + return false, fmt.Errorf("can't access %s: %w", path, ErrDirNotExist) } // Directory exists but can't be accessed - return true, fmt.Errorf("can't access %s: %w", path, errDirNoAccess) + return true, fmt.Errorf("can't access %s: %w", path, ErrDirNoAccess) } // RepoFinder finds git repositories inside a given path and loads their status. @@ -91,7 +95,7 @@ func (f *RepoFinder) Find() error { } if len(f.repos) == 0 { - return fmt.Errorf("no git repos found in root path %s", f.root) + return fmt.Errorf("%w in root path %s", ErrNoReposFound, f.root) } return nil diff --git a/pkg/git/finder_test.go b/pkg/git/finder_test.go index aa4d7d0..62d5d71 100644 --- a/pkg/git/finder_test.go +++ b/pkg/git/finder_test.go @@ -16,10 +16,6 @@ func TestFinder(t *testing.T) { want int }{ { - name: "no repos", - reposMaker: makeNoRepos, - want: 0, - }, { name: "single repos", reposMaker: makeSingleRepo, want: 1, @@ -59,7 +55,7 @@ func TestExists(t *testing.T) { { name: "dir does not exist", path: "/this/directory/does/not/exist", - want: errDirNotExist, + want: ErrDirNotExist, }, { name: "dir exists", path: os.TempDir(), @@ -76,12 +72,6 @@ func TestExists(t *testing.T) { } } -func makeNoRepos(t *testing.T) string { - root := test.TempDir(t, "") - - return root -} - func makeSingleRepo(t *testing.T) string { root := test.TempDir(t, "") diff --git a/pkg/list.go b/pkg/list.go index 7173b9d..0c3ff72 100644 --- a/pkg/list.go +++ b/pkg/list.go @@ -1,6 +1,7 @@ package pkg import ( + "errors" "fmt" "git-get/pkg/cfg" "git-get/pkg/git" @@ -8,6 +9,8 @@ import ( "strings" ) +var ErrInvalidOutput = errors.New("invalid output format") + // ListCfg provides configuration for the List command. type ListCfg struct { Fetch bool @@ -37,7 +40,7 @@ func List(conf *ListCfg) error { case cfg.OutDump: fmt.Print(print.NewDumpPrinter().Print(printables)) default: - return fmt.Errorf("invalid --out flag; allowed values: [%s]", strings.Join(cfg.AllowedOut, ", ")) + return fmt.Errorf("%w, allowed values: [%s]", ErrInvalidOutput, strings.Join(cfg.AllowedOut, ", ")) } return nil