Skip to content

Commit 59822bc

Browse files
committed
refactor: shorten and improve error messages to follow Go commandments
1 parent 5ab9a47 commit 59822bc

6 files changed

Lines changed: 17 additions & 17 deletions

File tree

‎src/skl/add.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func AddSkill(src string, opts AddOptions, cwd string) error {
169169
var err error
170170
cwd, err = os.Getwd()
171171
if err != nil {
172-
return fmt.Errorf("failed to get current working directory: %w", err)
172+
return fmt.Errorf("get working directory: %w", err)
173173
}
174174
}
175175

@@ -240,10 +240,10 @@ func AddSkill(src string, opts AddOptions, cwd string) error {
240240
for _, agentType := range targetAgents {
241241
res, err := installSkillForAgent(skillName, dir, agentType, opts, cwd)
242242
if err != nil {
243-
return fmt.Errorf("failed to install skill for agent %s: %w", agentType, err)
243+
return fmt.Errorf("install skill for agent %s: %w", agentType, err)
244244
}
245245
if !res.Success {
246-
return fmt.Errorf("failed to install skill %q for agent %s: %s", skillName, agentType, res.Error)
246+
return fmt.Errorf("install skill %q for agent %s: %s", skillName, agentType, res.Error)
247247
}
248248
if opts.Verbose {
249249
status := "Installed"
@@ -427,7 +427,7 @@ func downloadRemote(repoURL string, ref string, opts AddOptions) (string, error)
427427
resp, err := http.Get(zipURL)
428428
if err != nil {
429429
_ = os.RemoveAll(tmpDir)
430-
return "", fmt.Errorf("failed to fetch from remote URL: %w", err)
430+
return "", fmt.Errorf("fetch remote: %w", err)
431431
}
432432
defer resp.Body.Close()
433433

@@ -453,7 +453,7 @@ func downloadRemote(repoURL string, ref string, opts AddOptions) (string, error)
453453

454454
if err := extractZip(resp.Body, tmpDir, verbose); err != nil {
455455
_ = os.RemoveAll(tmpDir)
456-
return "", fmt.Errorf("failed to extract downloaded zip: %w", err)
456+
return "", fmt.Errorf("extract zip: %w", err)
457457
}
458458

459459
return tmpDir, nil

‎src/skl/experimental_install.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ func RestoreFromLock(args []string, cwd string) error {
1111
var err error
1212
cwd, err = os.Getwd()
1313
if err != nil {
14-
return fmt.Errorf("failed to get working directory: %w", err)
14+
return fmt.Errorf("get working directory: %w", err)
1515
}
1616
}
1717

1818
lock, err := ReadLocalLock(cwd)
1919
if err != nil {
20-
return fmt.Errorf("failed to read local lock file: %w", err)
20+
return fmt.Errorf("read lock: %w", err)
2121
}
2222

2323
if len(lock.Skills) == 0 {

‎src/skl/experimental_sync.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func SyncSkills(args []string, opts SyncOptions, cwd string) error {
100100
var err error
101101
cwd, err = os.Getwd()
102102
if err != nil {
103-
return fmt.Errorf("failed to get working directory: %w", err)
103+
return fmt.Errorf("get working directory: %w", err)
104104
}
105105
}
106106

@@ -109,7 +109,7 @@ func SyncSkills(args []string, opts SyncOptions, cwd string) error {
109109
}
110110
discovered, err := DiscoverNodeModuleSkills(cwd)
111111
if err != nil {
112-
return fmt.Errorf("failed to discover node_modules skills: %w", err)
112+
return fmt.Errorf("discover node_modules skills: %w", err)
113113
}
114114

115115
if len(discovered) == 0 {
@@ -121,7 +121,7 @@ func SyncSkills(args []string, opts SyncOptions, cwd string) error {
121121

122122
lock, err := ReadLocalLock(cwd)
123123
if err != nil {
124-
return fmt.Errorf("failed to read local lock: %w", err)
124+
return fmt.Errorf("read lock: %w", err)
125125
}
126126

127127
canonicalBase := GetCanonicalSkillsDir(false, cwd)

‎src/skl/init.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func InitSkill(opts InitOptions) (string, error) {
1919
var err error
2020
cwd, err = os.Getwd()
2121
if err != nil {
22-
return "", fmt.Errorf("failed to get current working directory: %w", err)
22+
return "", fmt.Errorf("get working directory: %w", err)
2323
}
2424
}
2525

@@ -48,7 +48,7 @@ func InitSkill(opts InitOptions) (string, error) {
4848
// Create directory if name was provided
4949
if hasName {
5050
if err := os.MkdirAll(skillDir, 0755); err != nil {
51-
return "", fmt.Errorf("failed to create skill directory: %w", err)
51+
return "", fmt.Errorf("create skill directory: %w", err)
5252
}
5353
}
5454

@@ -73,7 +73,7 @@ Describe when this skill should be used.
7373
`, skillName, skillName)
7474

7575
if err := os.WriteFile(skillFile, []byte(skillContent), 0644); err != nil {
76-
return "", fmt.Errorf("failed to write SKILL.md: %w", err)
76+
return "", fmt.Errorf("write skill template: %w", err)
7777
}
7878

7979
return skillFile, nil

‎src/skl/remove.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func RemoveSkills(skillNames []string, opts RemoveOptions, cwd string) error {
7575
var err error
7676
cwd, err = os.Getwd()
7777
if err != nil {
78-
return fmt.Errorf("failed to get working directory: %w", err)
78+
return fmt.Errorf("get working directory: %w", err)
7979
}
8080
}
8181

@@ -101,7 +101,7 @@ func RemoveSkills(skillNames []string, opts RemoveOptions, cwd string) error {
101101

102102
home, err := os.UserHomeDir()
103103
if err != nil {
104-
return fmt.Errorf("failed to resolve user home: %w", err)
104+
return fmt.Errorf("resolve user home: %w", err)
105105
}
106106

107107
configHome := os.Getenv("XDG_CONFIG_HOME")

‎src/skl/update.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ func UpdateSkill(name string, srcDir string, opts UpdateOptions) error {
5555
skillMd := filepath.Join(skillDir, "SKILL.md")
5656
bytes, err := os.ReadFile(skillMd)
5757
if err != nil {
58-
return fmt.Errorf("failed to read installed SKILL.md: %w", err)
58+
return fmt.Errorf("read installed skill: %w", err)
5959
}
6060

6161
// Write the exact same bytes back to update modification time and ensure write access
6262
if err := os.WriteFile(skillMd, bytes, 0644); err != nil {
63-
return fmt.Errorf("failed to refresh SKILL.md: %w", err)
63+
return fmt.Errorf("refresh skill: %w", err)
6464
}
6565

6666
return nil

0 commit comments

Comments
 (0)