diff --git a/src/pkg/packager/interactive.go b/src/pkg/packager/interactive.go index 45e3ee8fa5..bc29c8e0f8 100644 --- a/src/pkg/packager/interactive.go +++ b/src/pkg/packager/interactive.go @@ -6,7 +6,6 @@ package packager import ( "fmt" - "log/slog" "os" "path/filepath" @@ -24,7 +23,7 @@ func (p *Packager) confirmAction(stage string, warnings []string, sbomViewFiles message.HeaderInfof("📦 PACKAGE DEFINITION") err := utils.ColorPrintYAML(p.cfg.Pkg, p.getPackageYAMLHints(stage), true) if err != nil { - slog.Error("unable to print yaml", "error", err) + message.WarnErr(err, "unable to print yaml") } // Print any potential breaking changes (if this is a Deploy confirm) between this CLI version and the deployed init package diff --git a/src/pkg/utils/auth.go b/src/pkg/utils/auth.go index 78b20a4a1a..a6285ec35a 100644 --- a/src/pkg/utils/auth.go +++ b/src/pkg/utils/auth.go @@ -89,7 +89,7 @@ func credentialParser(path string) (_ []Credential, err error) { } // netrcParser parses a user's .netrc file using the method curl did pre 7.84.0: https://daniel.haxx.se/blog/2022/05/31/netrc-pains/. -func netrcParser(path string) ([]Credential, error) { +func netrcParser(path string) (_ []Credential, _ error) { file, err := os.Open(path) if errors.Is(err, os.ErrNotExist) { return nil, nil @@ -97,6 +97,10 @@ func netrcParser(path string) ([]Credential, error) { if err != nil { return nil, err } + defer func() { + err2 := file.Close() + err = errors.Join(err, err2) + }() var credentials []Credential scanner := bufio.NewScanner(file) @@ -157,12 +161,6 @@ func netrcParser(path string) ([]Credential, error) { } } - // Close our file and handle any errors now that we're done scanning - err = file.Close() - if err != nil { - return nil, err - } - // Append the last machine (if exists) at the end of the file if activeMachine != nil { credentials = appendNetrcMachine(activeMachine, credentials) diff --git a/src/pkg/utils/network.go b/src/pkg/utils/network.go index 5858431430..17aa9a6ac3 100644 --- a/src/pkg/utils/network.go +++ b/src/pkg/utils/network.go @@ -92,7 +92,7 @@ func DownloadToFile(ctx context.Context, src, dst, cosignKeyPath string) (err er } } - return err + return nil } func httpGetFile(url string, destinationFile *os.File) (err error) { diff --git a/src/pkg/variables/templates_test.go b/src/pkg/variables/templates_test.go index 524febf0fb..bb6c95a820 100644 --- a/src/pkg/variables/templates_test.go +++ b/src/pkg/variables/templates_test.go @@ -130,16 +130,20 @@ func TestReplaceTextTemplate(t *testing.T) { for _, tc := range tests { if tc.path == "" { - tmpDir := t.TempDir() - tc.path = filepath.Join(tmpDir, "templates.test") + func() { + tmpDir := t.TempDir() + tc.path = filepath.Join(tmpDir, "templates.test") - f, err := os.Create(tc.path) - require.NoError(t, err) + f, err := os.Create(tc.path) + require.NoError(t, err) - _, err = f.WriteString(start) - require.NoError(t, err) - err = f.Close() - require.NoError(t, err) + defer func() { + require.NoError(t, f.Close()) + }() + + _, err = f.WriteString(start) + require.NoError(t, err) + }() } gotErr := tc.vc.ReplaceTextTemplate(tc.path)