From d2334bb023e699bc8da84463ea7aa3f6dceff2de Mon Sep 17 00:00:00 2001 From: Kit Patella Date: Mon, 30 Sep 2024 13:15:36 -0700 Subject: [PATCH] chore: address some review comments Signed-off-by: Kit Patella --- src/cmd/destroy.go | 3 +-- src/cmd/dev.go | 5 ++--- src/cmd/internal.go | 3 +-- src/cmd/package.go | 17 ++++++++--------- src/cmd/tools/helm.go | 4 ++-- src/internal/gitea/gitea.go | 8 ++++---- src/pkg/layout/package.go | 3 +-- src/pkg/message/progress.go | 2 +- 8 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/cmd/destroy.go b/src/cmd/destroy.go index 3c051b9a5e..28ceb1c632 100644 --- a/src/cmd/destroy.go +++ b/src/cmd/destroy.go @@ -8,7 +8,6 @@ import ( "context" "errors" "fmt" - "log/slog" "os" "regexp" @@ -79,7 +78,7 @@ var destroyCmd = &cobra.Command{ // Try to remove the script, but ignore any errors and debug log them err = os.Remove(script) if err != nil { - slog.Debug("Unable to remove script", "script", script, "error", err) + message.Debug("Unable to remove script", "script", script, "error", err) } } } else { diff --git a/src/cmd/dev.go b/src/cmd/dev.go index 31c7c31a1a..ab0a262589 100644 --- a/src/cmd/dev.go +++ b/src/cmd/dev.go @@ -8,7 +8,6 @@ import ( "errors" "fmt" "io" - "log/slog" "os" "path/filepath" "strings" @@ -334,11 +333,11 @@ func init() { err := devFindImagesCmd.Flags().MarkDeprecated("set", "this field is replaced by create-set") if err != nil { - slog.Debug("Unable to mark dev-find-images flag as set", "error", err) + message.Debug("Unable to mark dev-find-images flag as set", "error", err) } err = devFindImagesCmd.Flags().MarkHidden("set") if err != nil { - slog.Debug("Unable to mark dev-find-images flag as hidden", "error", err) + message.Debug("Unable to mark dev-find-images flag as hidden", "error", err) } devFindImagesCmd.Flags().StringVarP(&pkgConfig.CreateOpts.Flavor, "flavor", "f", v.GetString(common.VPkgCreateFlavor), lang.CmdPackageCreateFlagFlavor) devFindImagesCmd.Flags().StringToStringVar(&pkgConfig.CreateOpts.SetVariables, "create-set", v.GetStringMapString(common.VPkgCreateSet), lang.CmdDevFlagSet) diff --git a/src/cmd/internal.go b/src/cmd/internal.go index 82e1e50596..b3bc2c4592 100644 --- a/src/cmd/internal.go +++ b/src/cmd/internal.go @@ -9,7 +9,6 @@ import ( "encoding/json" "errors" "fmt" - "log/slog" "os" "path/filepath" "strings" @@ -391,7 +390,7 @@ func addHiddenDummyFlag(cmd *cobra.Command, flagDummy string) { cmd.PersistentFlags().StringVar(&dummyStr, flagDummy, "", "") err := cmd.PersistentFlags().MarkHidden(flagDummy) if err != nil { - slog.Debug("Unable to add hidden dummy flag", "error", err) + message.Debug("Unable to add hidden dummy flag", "error", err) } } } diff --git a/src/cmd/package.go b/src/cmd/package.go index 8fbb3b1dd0..4eac63b43b 100644 --- a/src/cmd/package.go +++ b/src/cmd/package.go @@ -8,7 +8,6 @@ import ( "context" "errors" "fmt" - "log/slog" "os" "path/filepath" "regexp" @@ -388,19 +387,19 @@ func choosePackage(args []string) (string, error) { tarPath := config.ZarfPackagePrefix + toComplete + "*.tar" files, err := filepath.Glob(tarPath) if err != nil { - slog.Debug("Unable to glob", "tarPath", tarPath, "error", err) + message.Debug("Unable to glob", "tarPath", tarPath, "error", err) } zstPath := config.ZarfPackagePrefix + toComplete + "*.tar.zst" zstFiles, err := filepath.Glob(zstPath) if err != nil { - slog.Debug("Unable to glob", "zstPath", zstPath, "error", err) + message.Debug("Unable to glob", "zstPath", zstPath, "error", err) } splitPath := config.ZarfPackagePrefix + toComplete + "*.part000" splitFiles, err := filepath.Glob(splitPath) if err != nil { - slog.Debug("Unable to glob", "splitPath", splitPath, "error", err) + message.Debug("Unable to glob", "splitPath", splitPath, "error", err) } files = append(files, zstFiles...) @@ -428,7 +427,7 @@ func getPackageCompletionArgs(cmd *cobra.Command, _ []string, _ string) ([]strin deployedZarfPackages, err := c.GetDeployedZarfPackages(ctx) if err != nil { - slog.Error("Unable to get deployed zarf packages for package completion args", "error", err) + message.Debug("Unable to get deployed zarf packages for package completion args", "error", err) } // Populate list of package names for _, pkg := range deployedZarfPackages { @@ -500,15 +499,15 @@ func bindCreateFlags(v *viper.Viper) { errOD := createFlags.MarkHidden("output-directory") if errOD != nil { - slog.Debug("Unable to mark flag output-directory", "error", errOD) + message.Debug("Unable to mark flag output-directory", "error", errOD) } errKey := createFlags.MarkHidden("key") if errKey != nil { - slog.Debug("Unable to mark flag key", "error", errKey) + message.Debug("Unable to mark flag key", "error", errKey) } errKP := createFlags.MarkHidden("key-pass") if errKP != nil { - slog.Debug("Unable to mark flag key-pass", "error", errKP) + message.Debug("Unable to mark flag key-pass", "error", errKP) } } @@ -532,7 +531,7 @@ func bindDeployFlags(v *viper.Viper) { err := deployFlags.MarkHidden("sget") if err != nil { - slog.Debug("Unable to mark flag sget", "error", err) + message.Debug("Unable to mark flag sget", "error", err) } } diff --git a/src/cmd/tools/helm.go b/src/cmd/tools/helm.go index ee22acc56d..265a861b35 100644 --- a/src/cmd/tools/helm.go +++ b/src/cmd/tools/helm.go @@ -5,7 +5,7 @@ package tools import ( - "log/slog" + "github.com/zarf-dev/zarf/src/pkg/message" "os" "github.com/zarf-dev/zarf/src/cmd/tools/helm" @@ -27,7 +27,7 @@ func init() { // The inclusion of Helm in this manner should be changed once https://github.com/helm/helm/pull/12725 is merged helmCmd, err := helm.NewRootCmd(actionConfig, os.Stdout, helmArgs) if err != nil { - slog.Error("Failed to initialize helm command", "error", err) + message.Debug("Failed to initialize helm command", "error", err) } helmCmd.Short = lang.CmdToolsHelmShort helmCmd.Long = lang.CmdToolsHelmLong diff --git a/src/internal/gitea/gitea.go b/src/internal/gitea/gitea.go index 6aff480af6..48bfdfaae1 100644 --- a/src/internal/gitea/gitea.go +++ b/src/internal/gitea/gitea.go @@ -61,14 +61,14 @@ func (g *Client) DoRequest(ctx context.Context, method string, path string, body req.Header.Add("accept", "application/json") req.Header.Add("content-type", "application/json") resp, err := g.httpClient.Do(req) - // Ensure we close the body of the http client and capture the error + if err != nil { + return nil, 0, err + } defer func() { errClose := resp.Body.Close() err = errors.Join(err, errClose) }() - if err != nil { - return nil, 0, err - } + b, err := io.ReadAll(resp.Body) if err != nil { return nil, 0, err diff --git a/src/pkg/layout/package.go b/src/pkg/layout/package.go index af44e5063f..3c9598cf23 100644 --- a/src/pkg/layout/package.go +++ b/src/pkg/layout/package.go @@ -7,7 +7,6 @@ package layout import ( "errors" "fmt" - "log/slog" "os" "path/filepath" "slices" @@ -330,7 +329,7 @@ func (pp *PackagePaths) Files() map[string]string { stripBase := func(path string) string { rel, err := filepath.Rel(pp.Base, path) if err != nil { - slog.Debug("unable to strip base from path", "error", err) + message.Debug("unable to strip base from path", "error", err) } // Convert from the OS path separator to the standard '/' for Windows support return filepath.ToSlash(rel) diff --git a/src/pkg/message/progress.go b/src/pkg/message/progress.go index c5e1a5c4db..8e602c7cf5 100644 --- a/src/pkg/message/progress.go +++ b/src/pkg/message/progress.go @@ -36,7 +36,7 @@ func NewProgressBar(total int64, text string) *ProgressBar { WithWriter(os.Stderr). Start() if err != nil { - slog.Debug("Unable to create default progressbar", "error", err) + message.Debug("Unable to create default progressbar", "error", err) } }