fix: address CodeRabbit feedback - use errors.E for context
Add contextual error handling using errors.E helper as suggested: - config.go: Wrap LoadConfig read/parse errors - images.go: Wrap NewImageManager, loadManifest, and Manifest.Save errors Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
1adebbdba1
commit
b291ec0e62
2 changed files with 12 additions and 7 deletions
|
|
@ -4,6 +4,7 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/host-uk/core/pkg/errors"
|
||||
"github.com/host-uk/core/pkg/io"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
|
@ -75,12 +76,12 @@ func LoadConfig() (*Config, error) {
|
|||
if os.IsNotExist(err) {
|
||||
return DefaultConfig(), nil
|
||||
}
|
||||
return nil, err
|
||||
return nil, errors.E("devops.LoadConfig", "failed to read config", err)
|
||||
}
|
||||
|
||||
cfg := DefaultConfig()
|
||||
if err := yaml.Unmarshal([]byte(content), cfg); err != nil {
|
||||
return nil, err
|
||||
return nil, errors.E("devops.LoadConfig", "failed to parse config", err)
|
||||
}
|
||||
|
||||
return cfg, nil
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/host-uk/core/pkg/devops/sources"
|
||||
"github.com/host-uk/core/pkg/errors"
|
||||
"github.com/host-uk/core/pkg/io"
|
||||
)
|
||||
|
||||
|
|
@ -42,7 +43,7 @@ func NewImageManager(cfg *Config) (*ImageManager, error) {
|
|||
|
||||
// Ensure images directory exists
|
||||
if err := io.Local.EnsureDir(imagesDir); err != nil {
|
||||
return nil, err
|
||||
return nil, errors.E("devops.NewImageManager", "failed to create images directory", err)
|
||||
}
|
||||
|
||||
// Load or create manifest
|
||||
|
|
@ -172,11 +173,11 @@ func loadManifest(path string) (*Manifest, error) {
|
|||
if os.IsNotExist(err) {
|
||||
return m, nil
|
||||
}
|
||||
return nil, err
|
||||
return nil, errors.E("devops.loadManifest", "failed to read manifest", err)
|
||||
}
|
||||
|
||||
if err := json.Unmarshal([]byte(content), m); err != nil {
|
||||
return nil, err
|
||||
return nil, errors.E("devops.loadManifest", "failed to parse manifest", err)
|
||||
}
|
||||
m.path = path
|
||||
|
||||
|
|
@ -187,7 +188,10 @@ func loadManifest(path string) (*Manifest, error) {
|
|||
func (m *Manifest) Save() error {
|
||||
data, err := json.MarshalIndent(m, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
return errors.E("devops.Manifest.Save", "failed to marshal manifest", err)
|
||||
}
|
||||
return io.Local.Write(m.path, string(data))
|
||||
if err := io.Local.Write(m.path, string(data)); err != nil {
|
||||
return errors.E("devops.Manifest.Save", "failed to write manifest", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue