Skip to content

Commit efb64a1

Browse files
authored
Merge pull request #4689 from kersten/chore/pkg-error-msg-cleanup
🌱 (chore): wrap file and I/O errors with '%w' in 'pkg'
2 parents a042652 + 6ea9744 commit efb64a1

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

pkg/model/resource/gvk.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (gvk GVK) Validate() error {
5757
return errors.New(versionRequired)
5858
}
5959
if errs := validation.IsDNS1123Subdomain(gvk.Version); len(errs) > 0 && gvk.Version != versionInternal {
60-
return fmt.Errorf("Version must respect DNS-1123 (was %s)", gvk.Version)
60+
return fmt.Errorf("version must respect DNS-1123 (was %q)", gvk.Version)
6161
}
6262

6363
// Check if kind has a valid DNS1035 label value

pkg/plugins/external/helpers.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ type osWdGetter struct{}
7575
func (o *osWdGetter) GetCurrentDir() (string, error) {
7676
currentDir, err := os.Getwd()
7777
if err != nil {
78-
return "", fmt.Errorf("error getting current directory: %v", err)
78+
return "", fmt.Errorf("error getting current directory: %w", err)
7979
}
8080

8181
return currentDir, nil
@@ -163,7 +163,7 @@ func handlePluginResponse(fs machinery.Filesystem, req external.PluginRequest, p
163163

164164
currentDir, err := currentDirGetter.GetCurrentDir()
165165
if err != nil {
166-
return fmt.Errorf("error getting current directory: %v", err)
166+
return fmt.Errorf("error getting current directory: %w", err)
167167
}
168168

169169
for filename, data := range res.Universe {
@@ -172,7 +172,7 @@ func handlePluginResponse(fs machinery.Filesystem, req external.PluginRequest, p
172172

173173
// create the directory if it does not exist
174174
if err := os.MkdirAll(dir, 0o750); err != nil {
175-
return fmt.Errorf("error creating the directory: %v", err)
175+
return fmt.Errorf("error creating the directory: %w", err)
176176
}
177177

178178
f, err := fs.FS.Create(path)

pkg/plugins/optional/helm/v1alpha/scaffolds/init.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ func (s *initScaffolder) Scaffold() error {
118118
}
119119

120120
if err = scaffold.Execute(buildScaffold...); err != nil {
121-
return fmt.Errorf("error scaffolding helm-chart manifests: %v", err)
121+
return fmt.Errorf("error scaffolding helm-chart manifests: %w", err)
122122
}
123123

124124
// Copy relevant files from config/ to dist/chart/templates/
125125
err = s.copyConfigFiles()
126126
if err != nil {
127-
return fmt.Errorf("failed to copy manifests from config to dist/chart/templates/: %v", err)
127+
return fmt.Errorf("failed to copy manifests from config to dist/chart/templates/: %w", err)
128128
}
129129

130130
return nil
@@ -170,7 +170,7 @@ func (s *initScaffolder) extractWebhooksFromGeneratedFiles() (mutatingWebhooks [
170170
content, err := os.ReadFile(manifestFile)
171171
if err != nil {
172172
return nil, nil,
173-
fmt.Errorf("failed to read %s: %w", manifestFile, err)
173+
fmt.Errorf("failed to read %q: %w", manifestFile, err)
174174
}
175175

176176
docs := strings.Split(string(content), "---")
@@ -256,7 +256,7 @@ func (s *initScaffolder) copyConfigFiles() error {
256256

257257
// Ensure destination directory exists
258258
if err := os.MkdirAll(dir.DestDir, os.ModePerm); err != nil {
259-
return fmt.Errorf("failed to create directory %s: %v", dir.DestDir, err)
259+
return fmt.Errorf("failed to create directory %q: %w", dir.DestDir, err)
260260
}
261261

262262
for _, srcFile := range files {
@@ -462,23 +462,23 @@ func getCRDPatchContent(kind, group string) (string, bool, error) {
462462
groupKindPattern := fmt.Sprintf("config/crd/patches/webhook_*%s*%s*.yaml", group, kind)
463463
patchFiles, err := filepath.Glob(groupKindPattern)
464464
if err != nil {
465-
return "", false, fmt.Errorf("failed to list patches: %v", err)
465+
return "", false, fmt.Errorf("failed to list patches: %w", err)
466466
}
467467

468468
// If no group-specific patch found, search for patches that contain only "webhook" and the kind
469469
if len(patchFiles) == 0 {
470470
kindOnlyPattern := fmt.Sprintf("config/crd/patches/webhook_*%s*.yaml", kind)
471471
patchFiles, err = filepath.Glob(kindOnlyPattern)
472472
if err != nil {
473-
return "", false, fmt.Errorf("failed to list patches: %v", err)
473+
return "", false, fmt.Errorf("failed to list patches: %w", err)
474474
}
475475
}
476476

477477
// Read the first matching patch file (if any)
478478
if len(patchFiles) > 0 {
479479
patchContent, err := os.ReadFile(patchFiles[0])
480480
if err != nil {
481-
return "", false, fmt.Errorf("failed to read patch file %s: %v", patchFiles[0], err)
481+
return "", false, fmt.Errorf("failed to read patch file %q: %w", patchFiles[0], err)
482482
}
483483
return string(patchContent), true, nil
484484
}

0 commit comments

Comments
 (0)