Skip to content

Commit 091365e

Browse files
authored
Merge pull request #14 from adeeshperera/error-messages
fix #121 : improve error messages with context and actionable guidance
2 parents 192de2d + 7c9da93 commit 091365e

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

cmd/cli/store/store.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (s *StoreMethods) Save(LLMConfig LLMProvider) error {
8484
Data: []byte(LLMConfig.APIKey),
8585
})
8686
if err != nil {
87-
return errors.New("error storing credentials")
87+
return fmt.Errorf("failed to store credentials in keyring: %w", err)
8888
}
8989
updated = true
9090
break
@@ -99,7 +99,7 @@ func (s *StoreMethods) Save(LLMConfig LLMProvider) error {
9999
Data: []byte(LLMConfig.APIKey),
100100
})
101101
if err != nil {
102-
return errors.New("error storing credentials")
102+
return fmt.Errorf("failed to store credentials in keyring: %w", err)
103103
}
104104
}
105105

@@ -126,7 +126,7 @@ func (s *StoreMethods) DefaultLLMKey() (*LLMProvider, error) {
126126

127127
isConfigExists := StoreUtils.CheckConfig(configPath)
128128
if !isConfigExists {
129-
return nil, errors.New("config file Not exists")
129+
return nil, fmt.Errorf("config file does not exist at %s, run 'commit llm setup' to create it", configPath)
130130
}
131131

132132
data, err := os.ReadFile(configPath)
@@ -141,7 +141,7 @@ func (s *StoreMethods) DefaultLLMKey() (*LLMProvider, error) {
141141
return nil, fmt.Errorf("config file format error: %w. Please delete the config and run setup again", err)
142142
}
143143
} else {
144-
return nil, errors.New("config file is empty, Please add at least one LLM Key")
144+
return nil, errors.New("config file is empty, run 'commit llm setup' to add your first LLM provider")
145145
}
146146

147147
defaultLLM := cfg.Default
@@ -157,7 +157,7 @@ func (s *StoreMethods) DefaultLLMKey() (*LLMProvider, error) {
157157
return &useModel, nil
158158
}
159159
}
160-
return nil, errors.New("not found default model in config")
160+
return nil, fmt.Errorf("default model '%s' not found in saved providers, run 'commit llm setup' to configure it", defaultLLM)
161161
}
162162

163163
// ListSavedModels loads all persisted LLM provider configurations.
@@ -172,7 +172,7 @@ func ListSavedModels() (*Config, error) {
172172

173173
isConfigExists := StoreUtils.CheckConfig(configPath)
174174
if !isConfigExists {
175-
return nil, errors.New("config file not exists")
175+
return nil, fmt.Errorf("config file does not exist at %s, run 'commit llm setup' to create it", configPath)
176176
}
177177

178178
data, err := os.ReadFile(configPath)
@@ -187,7 +187,7 @@ func ListSavedModels() (*Config, error) {
187187
return nil, fmt.Errorf("config file format error: %w. Please delete the config and run setup again", err)
188188
}
189189
} else {
190-
return nil, errors.New("config file is empty, Please add at least one LLM Key")
190+
return nil, errors.New("config file is empty, run 'commit llm setup' to add your first LLM provider")
191191
}
192192

193193
return &cfg, nil
@@ -206,7 +206,7 @@ func ChangeDefault(Model types.LLMProvider) error {
206206

207207
isConfigExists := StoreUtils.CheckConfig(configPath)
208208
if !isConfigExists {
209-
return errors.New("config file not exists")
209+
return fmt.Errorf("config file does not exist at %s, run 'commit llm setup' to create it", configPath)
210210
}
211211

212212
data, err := os.ReadFile(configPath)
@@ -256,7 +256,7 @@ func (s *StoreMethods) DeleteModel(Model types.LLMProvider) error {
256256

257257
isConfigExists := StoreUtils.CheckConfig(configPath)
258258
if !isConfigExists {
259-
return errors.New("config file not exists")
259+
return fmt.Errorf("config file does not exist at %s, run 'commit llm setup' to create it", configPath)
260260
}
261261

262262
data, err := os.ReadFile(configPath)
@@ -318,7 +318,7 @@ func (s *StoreMethods) UpdateAPIKey(Model types.LLMProvider, APIKey string) erro
318318

319319
isConfigExists := StoreUtils.CheckConfig(configPath)
320320
if !isConfigExists {
321-
return errors.New("config file not exists")
321+
return fmt.Errorf("config file does not exist at %s, run 'commit llm setup' to create it", configPath)
322322
}
323323

324324
data, err := os.ReadFile(configPath)
@@ -342,7 +342,7 @@ func (s *StoreMethods) UpdateAPIKey(Model types.LLMProvider, APIKey string) erro
342342
Data: []byte(APIKey),
343343
})
344344
if err != nil {
345-
return errors.New("error storing credentials")
345+
return fmt.Errorf("failed to update credentials in keyring: %w", err)
346346
}
347347
updated = true
348348
}

0 commit comments

Comments
 (0)