Detailed changes
@@ -29,7 +29,7 @@ var Command = &cobra.Command{
abs, err := filepath.Abs(rp)
if err != nil {
- return err
+ return fmt.Errorf("failed to get absolute path: %w", err)
}
r, err := git.Open(abs)
@@ -64,7 +64,10 @@ var Command = &cobra.Command{
)
_, err = p.Run()
- return err
+ if err != nil {
+ return fmt.Errorf("program execution failed: %w", err)
+ }
+ return nil
},
}
@@ -1,6 +1,7 @@
package git
import (
+ "fmt"
"os"
"path/filepath"
@@ -12,14 +13,14 @@ func (r *Repository) Config() (*gcfg.Config, error) {
cp := filepath.Join(r.Path, "config")
f, err := os.Open(cp)
if err != nil {
- return nil, err
+ return nil, fmt.Errorf("failed to open git config file: %w", err)
}
defer f.Close()
d := gcfg.NewDecoder(f)
cfg := gcfg.New()
if err := d.Decode(cfg); err != nil {
- return nil, err
+ return nil, fmt.Errorf("failed to decode git config: %w", err)
}
return cfg, nil
@@ -30,10 +31,13 @@ func (r *Repository) SetConfig(cfg *gcfg.Config) error {
cp := filepath.Join(r.Path, "config")
f, err := os.Create(cp)
if err != nil {
- return err
+ return fmt.Errorf("failed to create git config file: %w", err)
}
defer f.Close()
e := gcfg.NewEncoder(f)
- return e.Encode(cfg)
+ if err := e.Encode(cfg); err != nil {
+ return fmt.Errorf("failed to encode git config: %w", err)
+ }
+ return nil
}
@@ -228,7 +228,7 @@ func IsVerbose() bool {
func parseFile(cfg *Config, path string) error {
f, err := os.Open(path)
if err != nil {
- return err
+ return fmt.Errorf("failed to open config file %s: %w", path, err)
}
defer f.Close()
@@ -284,9 +284,12 @@ func (c *Config) Parse() error {
// writeConfig writes the configuration to the given file.
func writeConfig(cfg *Config, path string) error {
if err := os.MkdirAll(filepath.Dir(path), os.ModePerm); err != nil {
- return err
+ return fmt.Errorf("failed to create config directory: %w", err)
}
- return os.WriteFile(path, []byte(newConfigFile(cfg)), 0o644) //nolint: errcheck, gosec
+ if err := os.WriteFile(path, []byte(newConfigFile(cfg)), 0o644); err != nil {
+ return fmt.Errorf("failed to write config file: %w", err)
+ }
+ return nil
}
// WriteConfig writes the configuration to the default file.
@@ -386,7 +389,7 @@ func (c *Config) Validate() error {
if !filepath.IsAbs(c.DataPath) {
dp, err := filepath.Abs(c.DataPath)
if err != nil {
- return err
+ return fmt.Errorf("failed to get absolute path for data directory: %w", err)
}
c.DataPath = dp
}