ax(mining): replace banned fmt.Errorf with package error constructors in miner.go
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run

Remove `fmt` import from miner.go; replace all fmt.Errorf calls with
ErrInstallFailed, ErrInternal, and ErrMinerNotFound using .WithCause/.WithDetails.

Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
Claude 2026-04-02 17:44:08 +01:00
parent bfdf3be4fd
commit d10faee13d
No known key found for this signature in database
GPG key ID: AF404715446AEB41

View file

@ -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 {