From d10faee13dbe79333df5bcf22f40e3b09b4edf91 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 2 Apr 2026 17:44:08 +0100 Subject: [PATCH] ax(mining): replace banned fmt.Errorf with package error constructors in miner.go Remove `fmt` import from miner.go; replace all fmt.Errorf calls with ErrInstallFailed, ErrInternal, and ErrMinerNotFound using .WithCause/.WithDetails. Co-Authored-By: Charon --- pkg/mining/miner.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/pkg/mining/miner.go b/pkg/mining/miner.go index 8d4d3ae..e88a7e6 100644 --- a/pkg/mining/miner.go +++ b/pkg/mining/miner.go @@ -5,7 +5,6 @@ import ( "archive/zip" "bytes" "compress/gzip" - "fmt" "io" "net/http" "os" @@ -260,7 +259,7 @@ func (b *BaseMiner) InstallFromURL(url string) error { if resp.StatusCode != http.StatusOK { _, _ = io.Copy(io.Discard, resp.Body) // Drain body to allow connection reuse (error ignored intentionally) - return fmt.Errorf("failed to download release: unexpected status code %d", resp.StatusCode) + return ErrInstallFailed(b.ExecutableName).WithDetails("unexpected status code " + strconv.Itoa(resp.StatusCode)) } if _, err := io.Copy(tmpfile, resp.Body); err != nil { @@ -280,7 +279,7 @@ func (b *BaseMiner) InstallFromURL(url string) error { err = b.untar(tmpfile.Name(), baseInstallPath) } if err != nil { - return fmt.Errorf("failed to extract miner: %w", err) + return ErrInstallFailed(b.ExecutableName).WithCause(err).WithDetails("failed to extract archive") } return nil @@ -376,14 +375,14 @@ func (b *BaseMiner) findMinerBinary() (string, error) { if err == nil { absPath, err := filepath.Abs(path) if err != nil { - return "", fmt.Errorf("failed to get absolute path for '%s': %w", path, err) + return "", ErrInternal("failed to get absolute path for '" + path + "'").WithCause(err) } logging.Debug("found miner binary in system PATH", logging.Fields{"path": absPath}) return absPath, nil } // If not found, return a detailed error - return "", fmt.Errorf("miner executable '%s' not found. Searched in: %s and system PATH", executableName, strings.Join(searchedPaths, ", ")) + return "", ErrMinerNotFound(executableName).WithDetails("searched in: " + strings.Join(searchedPaths, ", ") + " and system PATH") } // details, err := miner.CheckInstallation() @@ -556,11 +555,11 @@ func (b *BaseMiner) unzip(src, dest string) error { for _, f := range r.File { fpath := filepath.Join(dest, f.Name) if !strings.HasPrefix(fpath, filepath.Clean(dest)+string(os.PathSeparator)) { - return fmt.Errorf("%s: illegal file path", fpath) + return ErrInternal("illegal file path in archive").WithDetails(fpath) } if f.FileInfo().IsDir() { if err := os.MkdirAll(fpath, os.ModePerm); err != nil { - return fmt.Errorf("failed to create directory %s: %w", fpath, err) + return ErrInternal("failed to create directory").WithCause(err).WithDetails(fpath) } continue } @@ -614,7 +613,7 @@ func (b *BaseMiner) untar(src, dest string) error { target := filepath.Join(dest, header.Name) if !strings.HasPrefix(target, filepath.Clean(dest)+string(os.PathSeparator)) { - return fmt.Errorf("%s: illegal file path in archive", header.Name) + return ErrInternal("illegal file path in archive").WithDetails(header.Name) } switch header.Typeflag {