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 <charon@lethean.io>
This commit is contained in:
parent
cdeb66b82d
commit
a96af6adb2
1 changed files with 6 additions and 7 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue