Skip to content

Commit ee1100f

Browse files
committed
chore: normalize error messages and wrap errors using %w
- Use %w consistently in fmt.Errorf for proper error wrapping - Normalize error message casing for consistency - Adjust tests to reflect updated error strings
1 parent 6acdbd2 commit ee1100f

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

pkg/cli/alpha/internal/generate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ func copyFile(src, des string) error {
421421
func grafanaConfigMigrate(src, des string) error {
422422
grafanaConfig := fmt.Sprintf("%s/grafana/custom-metrics/config.yaml", src)
423423
if _, err := os.Stat(grafanaConfig); os.IsNotExist(err) {
424-
return fmt.Errorf("Grafana config path %s does not exist: %w", grafanaConfig, err)
424+
return fmt.Errorf("grafana config path %s does not exist: %w", grafanaConfig, err)
425425
}
426426
return copyFile(grafanaConfig, fmt.Sprintf("%s/grafana/custom-metrics/config.yaml", des))
427427
}
@@ -456,7 +456,7 @@ func hasHelmPlugin(cfg store.Store) bool {
456456
return false
457457
}
458458
// Log other errors if needed
459-
log.Errorf("Error decoding Helm plugin config: %v", err)
459+
log.Errorf("error decoding Helm plugin config: %v", err)
460460
return false
461461
}
462462

pkg/cli/cli.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ func (c *CLI) resolvePlugins() error {
352352
if _, version := plugin.SplitKey(pluginKey); version != "" {
353353
var ver plugin.Version
354354
if err := ver.Parse(version); err != nil {
355-
return fmt.Errorf("error parsing input plugin version from key %q: %v", pluginKey, err)
355+
return fmt.Errorf("error parsing input plugin version from key %q: %w", pluginKey, err)
356356
}
357357
if !ver.IsStable() {
358358
extraErrMsg += unstablePluginMsg

pkg/cli/options.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func WithPlugins(plugins ...plugin.Plugin) Option {
7676
return fmt.Errorf("two plugins have the same key: %q", key)
7777
}
7878
if err := plugin.Validate(p); err != nil {
79-
return fmt.Errorf("broken pre-set plugin %q: %v", key, err)
79+
return fmt.Errorf("broken pre-set plugin %q: %w", key, err)
8080
}
8181
c.plugins[key] = p
8282
}
@@ -97,7 +97,7 @@ func WithDefaultPlugins(projectVersion config.Version, plugins ...plugin.Plugin)
9797
}
9898
for _, p := range plugins {
9999
if err := plugin.Validate(p); err != nil {
100-
return fmt.Errorf("broken pre-set default plugin %q: %v", plugin.KeyFor(p), err)
100+
return fmt.Errorf("broken pre-set default plugin %q: %w", plugin.KeyFor(p), err)
101101
}
102102
if !plugin.SupportsVersion(p, projectVersion) {
103103
return fmt.Errorf("default plugin %q doesn't support version %q", plugin.KeyFor(p), projectVersion)
@@ -114,7 +114,7 @@ func WithDefaultPlugins(projectVersion config.Version, plugins ...plugin.Plugin)
114114
func WithDefaultProjectVersion(version config.Version) Option {
115115
return func(c *CLI) error {
116116
if err := version.Validate(); err != nil {
117-
return fmt.Errorf("broken pre-set default project version %q: %v", version, err)
117+
return fmt.Errorf("broken pre-set default project version %q: %w", version, err)
118118
}
119119
c.defaultProjectVersion = version
120120
return nil
@@ -209,7 +209,7 @@ func getPluginsRoot(host string) (pluginsRoot string, err error) {
209209
return "", fmt.Errorf("the specified path %s does not exist", pluginsPath)
210210
}
211211
// some other error
212-
return "", fmt.Errorf("error checking the path: %v", err)
212+
return "", fmt.Errorf("error checking the path: %w", err)
213213
}
214214
// the path exists
215215
return pluginsPath, nil
@@ -232,7 +232,7 @@ func getPluginsRoot(host string) (pluginsRoot string, err error) {
232232

233233
userHomeDir, err := os.UserHomeDir()
234234
if err != nil {
235-
return "", fmt.Errorf("error retrieving home dir: %v", err)
235+
return "", fmt.Errorf("error retrieving home dir: %w", err)
236236
}
237237

238238
return filepath.Join(userHomeDir, pluginsRoot), nil
@@ -294,13 +294,13 @@ func DiscoverExternalPlugins(filesystem afero.Fs) (ps []plugin.Plugin, err error
294294
// for example: sample.sh --> sample, externalplugin.py --> externalplugin
295295
trimmedPluginName := strings.Split(pluginFile.Name(), ".")
296296
if trimmedPluginName[0] == "" {
297-
return nil, fmt.Errorf("Invalid plugin name found %q", pluginFile.Name())
297+
return nil, fmt.Errorf("invalid plugin name found %q", pluginFile.Name())
298298
}
299299

300300
if pluginFile.Name() == pluginInfo.Name() || trimmedPluginName[0] == pluginInfo.Name() {
301301
// check whether the external plugin is an executable.
302302
if !isPluginExecutable(pluginFile.Mode()) {
303-
return nil, fmt.Errorf("External plugin %q found in path is not an executable", pluginFile.Name())
303+
return nil, fmt.Errorf("external plugin %q found in path is not an executable", pluginFile.Name())
304304
}
305305

306306
ep := external.Plugin{

pkg/cli/options_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ var _ = Describe("Discover external plugins", func() {
351351

352352
plugins, err = DiscoverExternalPlugins(filesystem.FS)
353353
Expect(err).To(HaveOccurred())
354-
Expect(err.Error()).To(ContainSubstring("Invalid plugin name found"))
354+
Expect(err.Error()).To(ContainSubstring("invalid plugin name found"))
355355
Expect(plugins).To(BeEmpty())
356356
})
357357
})

0 commit comments

Comments
 (0)