From a96af6adb241878c28e734bdca367cc015bf2675 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 2 Apr 2026 16:17:33 +0100 Subject: [PATCH] ax(mining): replace banned fmt.Errorf with project-native error constructors in profile_manager Removes the banned `fmt` import from profile_manager.go. All four fmt.Errorf calls are replaced with ErrInternal/ErrProfileNotFound, consistent with the error pattern used throughout the rest of the mining package. Co-Authored-By: Charon --- pkg/mining/profile_manager.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pkg/mining/profile_manager.go b/pkg/mining/profile_manager.go index ec1e926..08214aa 100644 --- a/pkg/mining/profile_manager.go +++ b/pkg/mining/profile_manager.go @@ -2,7 +2,6 @@ package mining import ( "encoding/json" - "fmt" "os" "path/filepath" "sync" @@ -26,7 +25,7 @@ type ProfileManager struct { func NewProfileManager() (*ProfileManager, error) { configPath, err := xdg.ConfigFile(filepath.Join("lethean-desktop", profileConfigFileName)) if err != nil { - return nil, fmt.Errorf("could not resolve config path: %w", err) + return nil, ErrInternal("could not resolve config path").WithCause(err) } profileManager := &ProfileManager{ @@ -37,7 +36,7 @@ func NewProfileManager() (*ProfileManager, error) { if err := profileManager.loadProfiles(); err != nil { // If the file doesn't exist, that's fine, but any other error is a problem. if !os.IsNotExist(err) { - return nil, fmt.Errorf("could not load profiles: %w", err) + return nil, ErrInternal("could not load profiles").WithCause(err) } } @@ -129,7 +128,7 @@ func (profileManager *ProfileManager) UpdateProfile(profile *MiningProfile) erro oldProfile, exists := profileManager.profiles[profile.ID] if !exists { - return fmt.Errorf("profile with ID %s not found", profile.ID) + return ErrProfileNotFound(profile.ID) } // Update in-memory state @@ -139,7 +138,7 @@ func (profileManager *ProfileManager) UpdateProfile(profile *MiningProfile) erro if err := profileManager.saveProfiles(); err != nil { // Restore old profile on save failure profileManager.profiles[profile.ID] = oldProfile - return fmt.Errorf("failed to save profile: %w", err) + return ErrInternal("failed to save profile").WithCause(err) } return nil @@ -152,7 +151,7 @@ func (profileManager *ProfileManager) DeleteProfile(id string) error { profile, exists := profileManager.profiles[id] if !exists { - return fmt.Errorf("profile with ID %s not found", id) + return ErrProfileNotFound(id) } delete(profileManager.profiles, id) @@ -160,7 +159,7 @@ func (profileManager *ProfileManager) DeleteProfile(id string) error { if err := profileManager.saveProfiles(); err != nil { // Restore profile on save failure profileManager.profiles[id] = profile - return fmt.Errorf("failed to delete profile: %w", err) + return ErrInternal("failed to delete profile").WithCause(err) } return nil