From 6373f1ae916c78d0afbb842a6dfec667124a5f10 Mon Sep 17 00:00:00 2001 From: Robert Sirchia Date: Tue, 16 Sep 2025 15:19:13 -0400 Subject: [PATCH] adding in error handling for fmt.Fprintln Signed-off-by: Robert Sirchia --- pkg/action/action.go | 20 +++++++-- pkg/action/dependency.go | 20 ++++++--- pkg/action/install.go | 2 +- pkg/action/pull.go | 12 +++-- pkg/action/show.go | 29 +++++++++--- pkg/action/verify.go | 15 +++++-- pkg/cmd/completion.go | 12 +++-- pkg/cmd/create.go | 7 ++- pkg/cmd/env.go | 4 +- pkg/cmd/get_hooks.go | 5 ++- pkg/cmd/get_manifest.go | 5 ++- pkg/cmd/get_notes.go | 5 ++- pkg/cmd/get_values.go | 4 +- pkg/cmd/install.go | 2 +- pkg/cmd/lint.go | 24 +++++++--- pkg/cmd/load_plugins.go | 2 +- pkg/cmd/package.go | 2 +- pkg/cmd/plugin_install.go | 35 ++++++++++++--- pkg/cmd/plugin_list.go | 5 ++- pkg/cmd/plugin_package.go | 12 +++-- pkg/cmd/plugin_uninstall.go | 5 ++- pkg/cmd/plugin_update.go | 5 ++- pkg/cmd/plugin_verify.go | 20 +++++++-- pkg/cmd/pull.go | 5 ++- pkg/cmd/push.go | 5 ++- pkg/cmd/repo_add.go | 14 ++++-- pkg/cmd/repo_list.go | 5 ++- pkg/cmd/repo_remove.go | 5 ++- pkg/cmd/repo_update.go | 11 +++-- pkg/cmd/rollback.go | 2 +- pkg/cmd/root.go | 2 +- pkg/cmd/show.go | 25 ++++++++--- pkg/cmd/template.go | 20 +++++++-- pkg/cmd/uninstall.go | 10 ++++- pkg/cmd/upgrade.go | 7 ++- pkg/cmd/verify.go | 5 ++- pkg/cmd/version.go | 5 ++- pkg/downloader/chart_downloader.go | 10 ++++- pkg/downloader/manager.go | 71 ++++++++++++++++++++++-------- pkg/engine/engine.go | 20 +++++++-- pkg/kube/client.go | 5 ++- pkg/registry/client.go | 42 ++++++++++++++---- pkg/registry/plugin.go | 25 ++++++++--- pkg/repo/v1/chartrepo.go | 5 ++- 44 files changed, 418 insertions(+), 133 deletions(-) diff --git a/pkg/action/action.go b/pkg/action/action.go index bcf6ca8ef..5088e5de3 100644 --- a/pkg/action/action.go +++ b/pkg/action/action.go @@ -281,7 +281,10 @@ func (cfg *Configuration) renderResources(ch *chart.Chart, values common.Values, if strings.TrimSpace(content) == "" { continue } - fmt.Fprintf(b, "---\n# Source: %s\n%s\n", name, content) + _, err := fmt.Fprintf(b, "---\n# Source: %s\n%s\n", name, content) + if err != nil { + return nil, nil, "", err + } } return hs, b, "", err } @@ -292,7 +295,10 @@ func (cfg *Configuration) renderResources(ch *chart.Chart, values common.Values, if includeCrds { for _, crd := range ch.CRDObjects() { if outputDir == "" { - fmt.Fprintf(b, "---\n# Source: %s\n%s\n", crd.Filename, string(crd.File.Data[:])) + _, err := fmt.Fprintf(b, "---\n# Source: %s\n%s\n", crd.Filename, string(crd.File.Data[:])) + if err != nil { + return nil, nil, "", err + } } else { err = writeToFile(outputDir, crd.Filename, string(crd.File.Data[:]), fileWritten[crd.Filename]) if err != nil { @@ -306,9 +312,15 @@ func (cfg *Configuration) renderResources(ch *chart.Chart, values common.Values, for _, m := range manifests { if outputDir == "" { if hideSecret && m.Head.Kind == "Secret" && m.Head.Version == "v1" { - fmt.Fprintf(b, "---\n# Source: %s\n# HIDDEN: The Secret output has been suppressed\n", m.Name) + _, err := fmt.Fprintf(b, "---\n# Source: %s\n# HIDDEN: The Secret output has been suppressed\n", m.Name) + if err != nil { + return nil, nil, "", err + } } else { - fmt.Fprintf(b, "---\n# Source: %s\n%s\n", m.Name, m.Content) + _, err := fmt.Fprintf(b, "---\n# Source: %s\n%s\n", m.Name, m.Content) + if err != nil { + return nil, nil, "", err + } } } else { newDir := outputDir diff --git a/pkg/action/dependency.go b/pkg/action/dependency.go index 03c370c8e..962cf1984 100644 --- a/pkg/action/dependency.go +++ b/pkg/action/dependency.go @@ -62,12 +62,18 @@ func (d *Dependency) List(chartpath string, out io.Writer) error { } if c.Metadata.Dependencies == nil { - fmt.Fprintf(out, "WARNING: no dependencies at %s\n", filepath.Join(chartpath, "charts")) + _, err := fmt.Fprintf(out, "WARNING: no dependencies at %s\n", filepath.Join(chartpath, "charts")) + if err != nil { + return err + } return nil } d.printDependencies(chartpath, out, c) - fmt.Fprintln(out) + _, err = fmt.Fprintln(out) + if err != nil { + return err + } d.printMissing(chartpath, out, c.Metadata.Dependencies) return nil } @@ -196,7 +202,7 @@ func (d *Dependency) printDependencies(chartpath string, out io.Writer, c *chart for _, row := range c.Metadata.Dependencies { table.AddRow(row.Name, row.Version, row.Repository, d.dependencyStatus(chartpath, row, c)) } - fmt.Fprintln(out, table) + _, _ = fmt.Fprintln(out, table) } // printMissing prints warnings about charts that are present on disk, but are @@ -205,14 +211,14 @@ func (d *Dependency) printMissing(chartpath string, out io.Writer, reqs []*chart folder := filepath.Join(chartpath, "charts/*") files, err := filepath.Glob(folder) if err != nil { - fmt.Fprintln(out, err) + _, _ = fmt.Fprintln(out, err) return } for _, f := range files { fi, err := os.Stat(f) if err != nil { - fmt.Fprintf(out, "Warning: %s\n", err) + _, _ = fmt.Fprintf(out, "Warning: %s\n", err) } // Skip anything that is not a directory and not a tgz file. if !fi.IsDir() && filepath.Ext(f) != ".tgz" { @@ -220,7 +226,7 @@ func (d *Dependency) printMissing(chartpath string, out io.Writer, reqs []*chart } c, err := loader.Load(f) if err != nil { - fmt.Fprintf(out, "WARNING: %q is not a chart.\n", f) + _, _ = fmt.Fprintf(out, "WARNING: %q is not a chart.\n", f) continue } found := false @@ -231,7 +237,7 @@ func (d *Dependency) printMissing(chartpath string, out io.Writer, reqs []*chart } } if !found { - fmt.Fprintf(out, "WARNING: %q is not in Chart.yaml.\n", f) + _, _ = fmt.Fprintf(out, "WARNING: %q is not in Chart.yaml.\n", f) } } } diff --git a/pkg/action/install.go b/pkg/action/install.go index 5ae12904d..1944f58d1 100644 --- a/pkg/action/install.go +++ b/pkg/action/install.go @@ -560,7 +560,7 @@ func (i *Install) failRelease(rel *release.Release, err error) (*release.Release } return rel, fmt.Errorf("release %s failed, and has been uninstalled due to rollback-on-failure being set: %w", i.ReleaseName, err) } - i.recordRelease(rel) // Ignore the error, since we have another error to deal with. + _ = i.recordRelease(rel) // Ignore the error, since we have another error to deal with. return rel, err } diff --git a/pkg/action/pull.go b/pkg/action/pull.go index be71d0ed0..a135a7beb 100644 --- a/pkg/action/pull.go +++ b/pkg/action/pull.go @@ -140,10 +140,16 @@ func (p *Pull) Run(chartRef string) (string, error) { if p.Verify { for name := range v.SignedBy.Identities { - fmt.Fprintf(&out, "Signed by: %v\n", name) + _, _ = fmt.Fprintf(&out, "Signed by: %v\n", name) + } + _, err := fmt.Fprintf(&out, "Using Key With Fingerprint: %X\n", v.SignedBy.PrimaryKey.Fingerprint) + if err != nil { + return "", err + } + _, err = fmt.Fprintf(&out, "Chart Hash Verified: %s\n", v.FileHash) + if err != nil { + return "", err } - fmt.Fprintf(&out, "Using Key With Fingerprint: %X\n", v.SignedBy.PrimaryKey.Fingerprint) - fmt.Fprintf(&out, "Chart Hash Verified: %s\n", v.FileHash) } // After verification, untar the chart into the requested directory. diff --git a/pkg/action/show.go b/pkg/action/show.go index 4195d69a5..0f4ba0311 100644 --- a/pkg/action/show.go +++ b/pkg/action/show.go @@ -95,12 +95,15 @@ func (s *Show) Run(chartpath string) (string, error) { var out strings.Builder if s.OutputFormat == ShowChart || s.OutputFormat == ShowAll { - fmt.Fprintf(&out, "%s\n", cf) + _, err := fmt.Fprintf(&out, "%s\n", cf) + if err != nil { + return "", err + } } if (s.OutputFormat == ShowValues || s.OutputFormat == ShowAll) && s.chart.Values != nil { if s.OutputFormat == ShowAll { - fmt.Fprintln(&out, "---") + _, _ = fmt.Fprintln(&out, "---") } if s.JSONPathTemplate != "" { printer, err := printers.NewJSONPathPrinter(s.JSONPathTemplate) @@ -111,7 +114,10 @@ func (s *Show) Run(chartpath string) (string, error) { } else { for _, f := range s.chart.Raw { if f.Name == chartutil.ValuesfileName { - fmt.Fprintln(&out, string(f.Data)) + _, err := fmt.Fprintln(&out, string(f.Data)) + if err != nil { + return "", err + } } } } @@ -121,9 +127,12 @@ func (s *Show) Run(chartpath string) (string, error) { readme := findReadme(s.chart.Files) if readme != nil { if s.OutputFormat == ShowAll { - fmt.Fprintln(&out, "---") + _, _ = fmt.Fprintln(&out, "---") + } + _, err := fmt.Fprintf(&out, "%s\n", readme.Data) + if err != nil { + return "", err } - fmt.Fprintf(&out, "%s\n", readme.Data) } } @@ -132,9 +141,15 @@ func (s *Show) Run(chartpath string) (string, error) { if len(crds) > 0 { for _, crd := range crds { if !bytes.HasPrefix(crd.File.Data, []byte("---")) { - fmt.Fprintln(&out, "---") + _, err := fmt.Fprintln(&out, "---") + if err != nil { + return "", err + } + } + _, err := fmt.Fprintf(&out, "%s\n", string(crd.File.Data)) + if err != nil { + return "", err } - fmt.Fprintf(&out, "%s\n", string(crd.File.Data)) } } } diff --git a/pkg/action/verify.go b/pkg/action/verify.go index ca2f4fa63..bf63830a0 100644 --- a/pkg/action/verify.go +++ b/pkg/action/verify.go @@ -45,10 +45,19 @@ func (v *Verify) Run(chartfile string) error { } for name := range p.SignedBy.Identities { - fmt.Fprintf(&out, "Signed by: %v\n", name) + _, err := fmt.Fprintf(&out, "Signed by: %v\n", name) + if err != nil { + return err + } + } + _, err = fmt.Fprintf(&out, "Using Key With Fingerprint: %X\n", p.SignedBy.PrimaryKey.Fingerprint) + if err != nil { + return err + } + _, err = fmt.Fprintf(&out, "Chart Hash Verified: %s\n", p.FileHash) + if err != nil { + return err } - fmt.Fprintf(&out, "Using Key With Fingerprint: %X\n", p.SignedBy.PrimaryKey.Fingerprint) - fmt.Fprintf(&out, "Chart Hash Verified: %s\n", p.FileHash) // TODO(mattfarina): The output is set as a property rather than returned // to maintain the Go API. In Helm v4 this function should return the out diff --git a/pkg/cmd/completion.go b/pkg/cmd/completion.go index 6f6dbd25d..6a2ef1b45 100644 --- a/pkg/cmd/completion.go +++ b/pkg/cmd/completion.go @@ -166,7 +166,10 @@ else complete -o default -o nospace -F __start_helm %[1]s fi ` - fmt.Fprintf(out, renamedBinaryHook, binary) + _, err := fmt.Fprintf(out, renamedBinaryHook, binary) + if err != nil { + return err + } } return err @@ -189,11 +192,14 @@ func runCompletionZsh(out io.Writer, cmd *cobra.Command) error { # the user renamed the helm binary compdef _helm %[1]s ` - fmt.Fprintf(out, renamedBinaryHook, binary) + _, err := fmt.Fprintf(out, renamedBinaryHook, binary) + if err != nil { + return err + } } // Cobra doesn't source zsh completion file, explicitly doing it here - fmt.Fprintf(out, "compdef _helm helm") + _, err = fmt.Fprintf(out, "compdef _helm helm") return err } diff --git a/pkg/cmd/create.go b/pkg/cmd/create.go index 435c8ca82..907e238ab 100644 --- a/pkg/cmd/create.go +++ b/pkg/cmd/create.go @@ -85,7 +85,10 @@ func newCreateCmd(out io.Writer) *cobra.Command { } func (o *createOptions) run(out io.Writer) error { - fmt.Fprintf(out, "Creating %s\n", o.name) + _, err := fmt.Fprintf(out, "Creating %s\n", o.name) + if err != nil { + return err + } chartname := filepath.Base(o.name) cfile := &chart.Metadata{ @@ -108,6 +111,6 @@ func (o *createOptions) run(out io.Writer) error { } chartutil.Stderr = out - _, err := chartutil.Create(chartname, filepath.Dir(o.name)) + _, err = chartutil.Create(chartname, filepath.Dir(o.name)) return err } diff --git a/pkg/cmd/env.go b/pkg/cmd/env.go index 8da201031..1dd23247b 100644 --- a/pkg/cmd/env.go +++ b/pkg/cmd/env.go @@ -53,10 +53,10 @@ func newEnvCmd(out io.Writer) *cobra.Command { keys := getSortedEnvVarKeys() for _, k := range keys { - fmt.Fprintf(out, "%s=\"%s\"\n", k, envVars[k]) + _, _ = fmt.Fprintf(out, "%s=\"%s\"\n", k, envVars[k]) } } else { - fmt.Fprintf(out, "%s\n", envVars[args[0]]) + _, _ = fmt.Fprintf(out, "%s\n", envVars[args[0]]) } }, } diff --git a/pkg/cmd/get_hooks.go b/pkg/cmd/get_hooks.go index 7ffefd93c..5d32e0e86 100644 --- a/pkg/cmd/get_hooks.go +++ b/pkg/cmd/get_hooks.go @@ -53,7 +53,10 @@ func newGetHooksCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { return err } for _, hook := range res.Hooks { - fmt.Fprintf(out, "---\n# Source: %s\n%s\n", hook.Path, hook.Manifest) + _, err := fmt.Fprintf(out, "---\n# Source: %s\n%s\n", hook.Path, hook.Manifest) + if err != nil { + return err + } } return nil }, diff --git a/pkg/cmd/get_manifest.go b/pkg/cmd/get_manifest.go index 021495d8d..ff8de25fa 100644 --- a/pkg/cmd/get_manifest.go +++ b/pkg/cmd/get_manifest.go @@ -54,7 +54,10 @@ func newGetManifestCmd(cfg *action.Configuration, out io.Writer) *cobra.Command if err != nil { return err } - fmt.Fprintln(out, res.Manifest) + _, err = fmt.Fprintln(out, res.Manifest) + if err != nil { + return err + } return nil }, } diff --git a/pkg/cmd/get_notes.go b/pkg/cmd/get_notes.go index ae79d8bcc..b14881377 100644 --- a/pkg/cmd/get_notes.go +++ b/pkg/cmd/get_notes.go @@ -51,7 +51,10 @@ func newGetNotesCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { return err } if len(res.Info.Notes) > 0 { - fmt.Fprintf(out, "NOTES:\n%s\n", res.Info.Notes) + _, err := fmt.Fprintf(out, "NOTES:\n%s\n", res.Info.Notes) + if err != nil { + return err + } } return nil }, diff --git a/pkg/cmd/get_values.go b/pkg/cmd/get_values.go index 02b195551..cd0274de6 100644 --- a/pkg/cmd/get_values.go +++ b/pkg/cmd/get_values.go @@ -82,9 +82,9 @@ func newGetValuesCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { func (v valuesWriter) WriteTable(out io.Writer) error { if v.allValues { - fmt.Fprintln(out, "COMPUTED VALUES:") + _, _ = fmt.Fprintln(out, "COMPUTED VALUES:") } else { - fmt.Fprintln(out, "USER-SUPPLIED VALUES:") + _, _ = fmt.Fprintln(out, "USER-SUPPLIED VALUES:") } return output.EncodeYAML(out, v.vals) } diff --git a/pkg/cmd/install.go b/pkg/cmd/install.go index c4e121c1f..6e2d6ba85 100644 --- a/pkg/cmd/install.go +++ b/pkg/cmd/install.go @@ -327,7 +327,7 @@ func runInstall(args []string, client *action.Install, valueOpts *values.Options signal.Notify(cSignal, os.Interrupt, syscall.SIGTERM) go func() { <-cSignal - fmt.Fprintf(out, "Release %s has been cancelled.\n", args[0]) + _, _ = fmt.Fprintf(out, "Release %s has been cancelled.\n", args[0]) cancel() }() diff --git a/pkg/cmd/lint.go b/pkg/cmd/lint.go index 71540f1be..7e0befd96 100644 --- a/pkg/cmd/lint.go +++ b/pkg/cmd/lint.go @@ -103,7 +103,10 @@ func newLintCmd(out io.Writer) *cobra.Command { continue } - fmt.Fprintf(&message, "==> Linting %s\n", path) + _, err := fmt.Fprintf(&message, "==> Linting %s\n", path) + if err != nil { + return err + } // All the Errors that are generated by a chart // that failed a lint will be included in the @@ -111,13 +114,16 @@ func newLintCmd(out io.Writer) *cobra.Command { // the Errors if there are no Messages. if len(result.Messages) == 0 { for _, err := range result.Errors { - fmt.Fprintf(&message, "Error %s\n", err) + _, _ = fmt.Fprintf(&message, "Error %s\n", err) } } for _, msg := range result.Messages { if !client.Quiet || msg.Severity > support.InfoSev { - fmt.Fprintf(&message, "%s\n", msg) + _, err := fmt.Fprintf(&message, "%s\n", msg) + if err != nil { + return err + } } } @@ -128,17 +134,23 @@ func newLintCmd(out io.Writer) *cobra.Command { // Adding extra new line here to break up the // results, stops this from being a big wall of // text and makes it easier to follow. - fmt.Fprint(&message, "\n") + _, _ = fmt.Fprint(&message, "\n") } - fmt.Fprint(out, message.String()) + _, err = fmt.Fprint(out, message.String()) + if err != nil { + return err + } summary := fmt.Sprintf("%d chart(s) linted, %d chart(s) failed", len(paths), failed) if failed > 0 { return errors.New(summary) } if !client.Quiet || errorsOrWarnings > 0 { - fmt.Fprintln(out, summary) + _, err := fmt.Fprintln(out, summary) + if err != nil { + return err + } } return nil }, diff --git a/pkg/cmd/load_plugins.go b/pkg/cmd/load_plugins.go index c0593f384..a07e6976d 100644 --- a/pkg/cmd/load_plugins.go +++ b/pkg/cmd/load_plugins.go @@ -63,7 +63,7 @@ func loadCLIPlugins(baseCmd *cobra.Command, out io.Writer) { } found, err := plugin.FindPlugins(dirs, descriptor) if err != nil { - fmt.Fprintf(os.Stderr, "failed to load plugins: %s\n", err) + _, _ = fmt.Fprintf(os.Stderr, "failed to load plugins: %s\n", err) return } diff --git a/pkg/cmd/package.go b/pkg/cmd/package.go index fc56e936a..6020c33d2 100644 --- a/pkg/cmd/package.go +++ b/pkg/cmd/package.go @@ -111,7 +111,7 @@ func newPackageCmd(out io.Writer) *cobra.Command { if err != nil { return err } - fmt.Fprintf(out, "Successfully packaged chart and saved it to: %s\n", p) + _, _ = fmt.Fprintf(out, "Successfully packaged chart and saved it to: %s\n", p) } return nil }, diff --git a/pkg/cmd/plugin_install.go b/pkg/cmd/plugin_install.go index 0abefa76b..b6a3f2b15 100644 --- a/pkg/cmd/plugin_install.go +++ b/pkg/cmd/plugin_install.go @@ -133,7 +133,10 @@ func (o *pluginInstallOptions) run(out io.Writer) error { if localInst, ok := i.(*installer.LocalInstaller); ok && !localInst.SupportsVerification() { // Local directory installations are allowed without verification shouldVerify = false - fmt.Fprintf(out, "Installing plugin from local directory (development mode)\n") + _, err := fmt.Fprintf(out, "Installing plugin from local directory (development mode)\n") + if err != nil { + return err + } } else if shouldVerify { // For remote installations, check if verification is supported if verifier, ok := i.(installer.Verifier); !ok || !verifier.SupportsVerification() { @@ -141,7 +144,10 @@ func (o *pluginInstallOptions) run(out io.Writer) error { } } else { // User explicitly disabled verification - fmt.Fprintf(out, "WARNING: Skipping plugin signature verification\n") + _, err := fmt.Fprintf(out, "WARNING: Skipping plugin signature verification\n") + if err != nil { + return err + } } // Set up installation options @@ -152,7 +158,10 @@ func (o *pluginInstallOptions) run(out io.Writer) error { // If verify is requested, show verification output if shouldVerify { - fmt.Fprintf(out, "Verifying plugin signature...\n") + _, err := fmt.Fprintf(out, "Verifying plugin signature...\n") + if err != nil { + return err + } } // Install the plugin with options @@ -164,10 +173,19 @@ func (o *pluginInstallOptions) run(out io.Writer) error { // If verification was successful, show the details if verifyResult != nil { for _, signer := range verifyResult.SignedBy { - fmt.Fprintf(out, "Signed by: %s\n", signer) + _, err := fmt.Fprintf(out, "Signed by: %s\n", signer) + if err != nil { + return err + } + } + _, err := fmt.Fprintf(out, "Using Key With Fingerprint: %s\n", verifyResult.Fingerprint) + if err != nil { + return err + } + _, err = fmt.Fprintf(out, "Plugin Hash Verified: %s\n", verifyResult.FileHash) + if err != nil { + return err } - fmt.Fprintf(out, "Using Key With Fingerprint: %s\n", verifyResult.Fingerprint) - fmt.Fprintf(out, "Plugin Hash Verified: %s\n", verifyResult.FileHash) } slog.Debug("loading plugin", "path", i.Path()) @@ -180,6 +198,9 @@ func (o *pluginInstallOptions) run(out io.Writer) error { return err } - fmt.Fprintf(out, "Installed plugin: %s\n", p.Metadata().Name) + _, err = fmt.Fprintf(out, "Installed plugin: %s\n", p.Metadata().Name) + if err != nil { + return err + } return nil } diff --git a/pkg/cmd/plugin_list.go b/pkg/cmd/plugin_list.go index 74e969e04..ba4201198 100644 --- a/pkg/cmd/plugin_list.go +++ b/pkg/cmd/plugin_list.go @@ -65,7 +65,10 @@ func newPluginListCmd(out io.Writer) *cobra.Command { } table.AddRow(m.Name, m.Version, m.Type, m.APIVersion, signedStatus, sourceURL) } - fmt.Fprintln(out, table) + _, err = fmt.Fprintln(out, table) + if err != nil { + return err + } return nil }, } diff --git a/pkg/cmd/plugin_package.go b/pkg/cmd/plugin_package.go index 05f8bb5ad..4a9f6d255 100644 --- a/pkg/cmd/plugin_package.go +++ b/pkg/cmd/plugin_package.go @@ -119,7 +119,7 @@ func (o *pluginPackageOptions) run(out io.Writer) error { } } else { // User explicitly disabled signing - fmt.Fprintf(out, "WARNING: Skipping plugin signing. This is not recommended for plugins intended for distribution.\n") + _, _ = fmt.Fprintf(out, "WARNING: Skipping plugin signing. This is not recommended for plugins intended for distribution.\n") } // Now create the tarball (only after signing prerequisites are met) @@ -163,10 +163,16 @@ func (o *pluginPackageOptions) run(out io.Writer) error { return err } - fmt.Fprintf(out, "Successfully signed. Signature written to: %s\n", provFile) + _, err = fmt.Fprintf(out, "Successfully signed. Signature written to: %s\n", provFile) + if err != nil { + return err + } } - fmt.Fprintf(out, "Successfully packaged plugin and saved it to: %s\n", tarballPath) + _, err = fmt.Fprintf(out, "Successfully packaged plugin and saved it to: %s\n", tarballPath) + if err != nil { + return err + } return nil } diff --git a/pkg/cmd/plugin_uninstall.go b/pkg/cmd/plugin_uninstall.go index 85eb46219..af62af0f8 100644 --- a/pkg/cmd/plugin_uninstall.go +++ b/pkg/cmd/plugin_uninstall.go @@ -72,7 +72,10 @@ func (o *pluginUninstallOptions) run(out io.Writer) error { if err := uninstallPlugin(found); err != nil { errorPlugins = append(errorPlugins, fmt.Errorf("failed to uninstall plugin %s, got error (%v)", name, err)) } else { - fmt.Fprintf(out, "Uninstalled plugin: %s\n", name) + _, err := fmt.Fprintf(out, "Uninstalled plugin: %s\n", name) + if err != nil { + return err + } } } else { errorPlugins = append(errorPlugins, fmt.Errorf("plugin: %s not found", name)) diff --git a/pkg/cmd/plugin_update.go b/pkg/cmd/plugin_update.go index c6d4b8530..158a0cec5 100644 --- a/pkg/cmd/plugin_update.go +++ b/pkg/cmd/plugin_update.go @@ -74,7 +74,10 @@ func (o *pluginUpdateOptions) run(out io.Writer) error { if err := updatePlugin(found); err != nil { errorPlugins = append(errorPlugins, fmt.Errorf("failed to update plugin %s, got error (%v)", name, err)) } else { - fmt.Fprintf(out, "Updated plugin: %s\n", name) + _, err := fmt.Fprintf(out, "Updated plugin: %s\n", name) + if err != nil { + return err + } } } else { errorPlugins = append(errorPlugins, fmt.Errorf("plugin: %s not found", name)) diff --git a/pkg/cmd/plugin_verify.go b/pkg/cmd/plugin_verify.go index 5f89e743e..be82dfc0f 100644 --- a/pkg/cmd/plugin_verify.go +++ b/pkg/cmd/plugin_verify.go @@ -108,15 +108,27 @@ func (o *pluginVerifyOptions) run(out io.Writer) error { // Output verification details for name := range verification.SignedBy.Identities { - fmt.Fprintf(out, "Signed by: %v\n", name) + _, err := fmt.Fprintf(out, "Signed by: %v\n", name) + if err != nil { + return err + } + } + _, err = fmt.Fprintf(out, "Using Key With Fingerprint: %X\n", verification.SignedBy.PrimaryKey.Fingerprint) + if err != nil { + return err } - fmt.Fprintf(out, "Using Key With Fingerprint: %X\n", verification.SignedBy.PrimaryKey.Fingerprint) // Only show hash for tarballs if verification.FileHash != "" { - fmt.Fprintf(out, "Plugin Hash Verified: %s\n", verification.FileHash) + _, err := fmt.Fprintf(out, "Plugin Hash Verified: %s\n", verification.FileHash) + if err != nil { + return err + } } else { - fmt.Fprintf(out, "Plugin Metadata Verified: %s\n", verification.FileName) + _, err := fmt.Fprintf(out, "Plugin Metadata Verified: %s\n", verification.FileName) + if err != nil { + return err + } } return nil diff --git a/pkg/cmd/pull.go b/pkg/cmd/pull.go index e3d93c049..8b81b1706 100644 --- a/pkg/cmd/pull.go +++ b/pkg/cmd/pull.go @@ -77,7 +77,10 @@ func newPullCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { if err != nil { return err } - fmt.Fprint(out, output) + _, err = fmt.Fprint(out, output) + if err != nil { + return err + } } return nil }, diff --git a/pkg/cmd/push.go b/pkg/cmd/push.go index 94d322b9d..ec27aeb1b 100644 --- a/pkg/cmd/push.go +++ b/pkg/cmd/push.go @@ -90,7 +90,10 @@ func newPushCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { if err != nil { return err } - fmt.Fprint(out, output) + _, err = fmt.Fprint(out, output) + if err != nil { + return err + } return nil }, } diff --git a/pkg/cmd/repo_add.go b/pkg/cmd/repo_add.go index 00e698daf..95053dca9 100644 --- a/pkg/cmd/repo_add.go +++ b/pkg/cmd/repo_add.go @@ -158,9 +158,9 @@ func (o *repoAddOptions) run(out io.Writer) error { o.password = password } else { fd := int(os.Stdin.Fd()) - fmt.Fprint(out, "Password: ") + _, _ = fmt.Fprint(out, "Password: ") password, err := term.ReadPassword(fd) - fmt.Fprintln(out) + _, _ = fmt.Fprintln(out) if err != nil { return err } @@ -197,7 +197,10 @@ func (o *repoAddOptions) run(out io.Writer) error { } // The add is idempotent so do nothing - fmt.Fprintf(out, "%q already exists with the same configuration, skipping\n", o.name) + _, err := fmt.Fprintf(out, "%q already exists with the same configuration, skipping\n", o.name) + if err != nil { + return err + } return nil } @@ -218,6 +221,9 @@ func (o *repoAddOptions) run(out io.Writer) error { if err := f.WriteFile(o.repoFile, 0o600); err != nil { return err } - fmt.Fprintf(out, "%q has been added to your repositories\n", o.name) + _, err = fmt.Fprintf(out, "%q has been added to your repositories\n", o.name) + if err != nil { + return err + } return nil } diff --git a/pkg/cmd/repo_list.go b/pkg/cmd/repo_list.go index 10b4442a0..203fd77fb 100644 --- a/pkg/cmd/repo_list.go +++ b/pkg/cmd/repo_list.go @@ -42,7 +42,10 @@ func newRepoListCmd(out io.Writer) *cobra.Command { // repositories will be 0. f, _ := repo.LoadFile(settings.RepositoryConfig) if len(f.Repositories) == 0 && outfmt != output.JSON && outfmt != output.YAML { - fmt.Fprintln(cmd.ErrOrStderr(), "no repositories to show") + _, err := fmt.Fprintln(cmd.ErrOrStderr(), "no repositories to show") + if err != nil { + return err + } return nil } diff --git a/pkg/cmd/repo_remove.go b/pkg/cmd/repo_remove.go index 330e69d3a..d7215c320 100644 --- a/pkg/cmd/repo_remove.go +++ b/pkg/cmd/repo_remove.go @@ -75,7 +75,10 @@ func (o *repoRemoveOptions) run(out io.Writer) error { if err := removeRepoCache(o.repoCache, name); err != nil { return err } - fmt.Fprintf(out, "%q has been removed from your repositories\n", name) + _, err := fmt.Fprintf(out, "%q has been removed from your repositories\n", name) + if err != nil { + return err + } } return nil diff --git a/pkg/cmd/repo_update.go b/pkg/cmd/repo_update.go index f2e7c0e0f..a4e506022 100644 --- a/pkg/cmd/repo_update.go +++ b/pkg/cmd/repo_update.go @@ -114,7 +114,7 @@ func (o *repoUpdateOptions) run(out io.Writer) error { } func updateCharts(repos []*repo.ChartRepository, out io.Writer) error { - fmt.Fprintln(out, "Hang tight while we grab the latest from your chart repositories...") + _, _ = fmt.Fprintln(out, "Hang tight while we grab the latest from your chart repositories...") var wg sync.WaitGroup failRepoURLChan := make(chan string, len(repos)) @@ -126,12 +126,12 @@ func updateCharts(repos []*repo.ChartRepository, out io.Writer) error { if _, err := re.DownloadIndexFile(); err != nil { writeMutex.Lock() defer writeMutex.Unlock() - fmt.Fprintf(out, "...Unable to get an update from the %q chart repository (%s):\n\t%s\n", re.Config.Name, re.Config.URL, err) + _, _ = fmt.Fprintf(out, "...Unable to get an update from the %q chart repository (%s):\n\t%s\n", re.Config.Name, re.Config.URL, err) failRepoURLChan <- re.Config.URL } else { writeMutex.Lock() defer writeMutex.Unlock() - fmt.Fprintf(out, "...Successfully got an update from the %q chart repository\n", re.Config.Name) + _, _ = fmt.Fprintf(out, "...Successfully got an update from the %q chart repository\n", re.Config.Name) } }(re) } @@ -151,7 +151,10 @@ func updateCharts(repos []*repo.ChartRepository, out io.Writer) error { repoFailList) } - fmt.Fprintln(out, "Update Complete. ⎈Happy Helming!⎈") + _, err := fmt.Fprintln(out, "Update Complete. ⎈Happy Helming!⎈") + if err != nil { + return err + } return nil } diff --git a/pkg/cmd/rollback.go b/pkg/cmd/rollback.go index ff60aaedf..c5b4656a7 100644 --- a/pkg/cmd/rollback.go +++ b/pkg/cmd/rollback.go @@ -70,7 +70,7 @@ func newRollbackCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { return err } - fmt.Fprintf(out, "Rollback was a success! Happy Helming!\n") + _, _ = fmt.Fprintf(out, "Rollback was a success! Happy Helming!\n") return nil }, } diff --git a/pkg/cmd/root.go b/pkg/cmd/root.go index 4f1be88d6..b9eb462e6 100644 --- a/pkg/cmd/root.go +++ b/pkg/cmd/root.go @@ -377,7 +377,7 @@ func checkForExpiredRepos(repofile string) { } if url := r.URL; strings.Contains(url, exp.old) { - fmt.Fprintf( + _, _ = fmt.Fprintf( os.Stderr, "WARNING: %q is deprecated for %q and will be deleted Nov. 13, 2020.\nWARNING: You should switch to %q via:\nWARNING: helm repo add %q %q --force-update\n", exp.old, diff --git a/pkg/cmd/show.go b/pkg/cmd/show.go index 1c7e7be44..40f11299f 100644 --- a/pkg/cmd/show.go +++ b/pkg/cmd/show.go @@ -92,7 +92,10 @@ func newShowCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { if err != nil { return err } - fmt.Fprint(out, output) + _, err = fmt.Fprint(out, output) + if err != nil { + return err + } return nil }, } @@ -113,7 +116,10 @@ func newShowCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { if err != nil { return err } - fmt.Fprint(out, output) + _, err = fmt.Fprint(out, output) + if err != nil { + return err + } return nil }, } @@ -134,7 +140,10 @@ func newShowCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { if err != nil { return err } - fmt.Fprint(out, output) + _, err = fmt.Fprint(out, output) + if err != nil { + return err + } return nil }, } @@ -155,7 +164,10 @@ func newShowCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { if err != nil { return err } - fmt.Fprint(out, output) + _, err = fmt.Fprint(out, output) + if err != nil { + return err + } return nil }, } @@ -176,7 +188,10 @@ func newShowCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { if err != nil { return err } - fmt.Fprint(out, output) + _, err = fmt.Fprint(out, output) + if err != nil { + return err + } return nil }, } diff --git a/pkg/cmd/template.go b/pkg/cmd/template.go index 81c112d51..cdbe64eb2 100644 --- a/pkg/cmd/template.go +++ b/pkg/cmd/template.go @@ -108,7 +108,10 @@ func newTemplateCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { // we always want to print the YAML, even if it is not valid. The error is still returned afterwards. if rel != nil { var manifests bytes.Buffer - fmt.Fprintln(&manifests, strings.TrimSpace(rel.Manifest)) + _, err := fmt.Fprintln(&manifests, strings.TrimSpace(rel.Manifest)) + if err != nil { + return err + } if !client.DisableHooks { fileWritten := make(map[string]bool) for _, m := range rel.Hooks { @@ -116,7 +119,10 @@ func newTemplateCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { continue } if client.OutputDir == "" { - fmt.Fprintf(&manifests, "---\n# Source: %s\n%s\n", m.Path, m.Manifest) + _, err := fmt.Fprintf(&manifests, "---\n# Source: %s\n%s\n", m.Path, m.Manifest) + if err != nil { + return err + } } else { newDir := client.OutputDir if client.UseReleaseName { @@ -181,10 +187,16 @@ func newTemplateCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { } } for _, m := range manifestsToRender { - fmt.Fprintf(out, "---\n%s\n", m) + _, err := fmt.Fprintf(out, "---\n%s\n", m) + if err != nil { + return err + } } } else { - fmt.Fprintf(out, "%s", manifests.String()) + _, err := fmt.Fprintf(out, "%s", manifests.String()) + if err != nil { + return err + } } } diff --git a/pkg/cmd/uninstall.go b/pkg/cmd/uninstall.go index 4680c324a..c24464591 100644 --- a/pkg/cmd/uninstall.go +++ b/pkg/cmd/uninstall.go @@ -62,10 +62,16 @@ func newUninstallCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { return err } if res != nil && res.Info != "" { - fmt.Fprintln(out, res.Info) + _, err := fmt.Fprintln(out, res.Info) + if err != nil { + return err + } } - fmt.Fprintf(out, "release \"%s\" uninstalled\n", args[i]) + _, err = fmt.Fprintf(out, "release \"%s\" uninstalled\n", args[i]) + if err != nil { + return err + } } return nil }, diff --git a/pkg/cmd/upgrade.go b/pkg/cmd/upgrade.go index c8fbf8bd3..aaa27d11f 100644 --- a/pkg/cmd/upgrade.go +++ b/pkg/cmd/upgrade.go @@ -241,7 +241,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { signal.Notify(cSignal, os.Interrupt, syscall.SIGTERM) go func() { <-cSignal - fmt.Fprintf(out, "Release %s has been cancelled.\n", args[0]) + _, _ = fmt.Fprintf(out, "Release %s has been cancelled.\n", args[0]) cancel() }() @@ -251,7 +251,10 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { } if outfmt == output.Table { - fmt.Fprintf(out, "Release %q has been upgraded. Happy Helming!\n", args[0]) + _, err := fmt.Fprintf(out, "Release %q has been upgraded. Happy Helming!\n", args[0]) + if err != nil { + return err + } } return outfmt.Write(out, &statusPrinter{ diff --git a/pkg/cmd/verify.go b/pkg/cmd/verify.go index 50f1ea914..e6c2d24d1 100644 --- a/pkg/cmd/verify.go +++ b/pkg/cmd/verify.go @@ -58,7 +58,10 @@ func newVerifyCmd(out io.Writer) *cobra.Command { return err } - fmt.Fprint(out, client.Out) + _, err = fmt.Fprint(out, client.Out) + if err != nil { + return err + } return nil }, diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go index 0211716fe..f9aed3db8 100644 --- a/pkg/cmd/version.go +++ b/pkg/cmd/version.go @@ -87,7 +87,10 @@ func (o *versionOptions) run(out io.Writer) error { } return tt.Execute(out, version.Get()) } - fmt.Fprintln(out, formatVersion(o.short)) + _, err := fmt.Fprintln(out, formatVersion(o.short)) + if err != nil { + return err + } return nil } diff --git a/pkg/downloader/chart_downloader.go b/pkg/downloader/chart_downloader.go index 00c8c56e8..bfcfadc3a 100644 --- a/pkg/downloader/chart_downloader.go +++ b/pkg/downloader/chart_downloader.go @@ -181,7 +181,10 @@ func (c *ChartDownloader) DownloadTo(ref, version, dest string) (string, *proven if c.Verify == VerifyAlways { return destfile, ver, fmt.Errorf("failed to fetch provenance %q", u.String()+".prov") } - fmt.Fprintf(c.Out, "WARNING: Verification not found for %s: %s\n", ref, err) + _, err := fmt.Fprintf(c.Out, "WARNING: Verification not found for %s: %s\n", ref, err) + if err != nil { + return "", nil, err + } return destfile, ver, nil } } @@ -284,7 +287,10 @@ func (c *ChartDownloader) DownloadToCache(ref, version string) (string, *provena if c.Verify == VerifyAlways { return pth, ver, fmt.Errorf("failed to fetch provenance %q", u.String()+".prov") } - fmt.Fprintf(c.Out, "WARNING: Verification not found for %s: %s\n", ref, err) + _, err := fmt.Fprintf(c.Out, "WARNING: Verification not found for %s: %s\n", ref, err) + if err != nil { + return "", nil, err + } return pth, ver, nil } diff --git a/pkg/downloader/manager.go b/pkg/downloader/manager.go index d41b8fdb4..97d0b17f3 100644 --- a/pkg/downloader/manager.go +++ b/pkg/downloader/manager.go @@ -270,13 +270,19 @@ func (m *Manager) downloadAll(deps []*chart.Dependency) error { } defer os.RemoveAll(tmpPath) - fmt.Fprintf(m.Out, "Saving %d charts\n", len(deps)) + _, err = fmt.Fprintf(m.Out, "Saving %d charts\n", len(deps)) + if err != nil { + return err + } var saveError error churls := make(map[string]struct{}) for _, dep := range deps { // No repository means the chart is in charts directory if dep.Repository == "" { - fmt.Fprintf(m.Out, "Dependency %s did not declare a repository. Assuming it exists in the charts directory\n", dep.Name) + _, err := fmt.Fprintf(m.Out, "Dependency %s did not declare a repository. Assuming it exists in the charts directory\n", dep.Name) + if err != nil { + return err + } // NOTE: we are only validating the local dependency conforms to the constraints. No copying to tmpPath is necessary. chartPath := filepath.Join(destPath, dep.Name) ch, err := loader.LoadDir(chartPath) @@ -302,7 +308,10 @@ func (m *Manager) downloadAll(deps []*chart.Dependency) error { } if strings.HasPrefix(dep.Repository, "file://") { if m.Debug { - fmt.Fprintf(m.Out, "Archiving %s from repo %s\n", dep.Name, dep.Repository) + _, err := fmt.Fprintf(m.Out, "Archiving %s from repo %s\n", dep.Name, dep.Repository) + if err != nil { + return err + } } ver, err := tarFromLocalDir(m.ChartPath, dep.Name, dep.Repository, dep.Version, tmpPath) if err != nil { @@ -322,11 +331,17 @@ func (m *Manager) downloadAll(deps []*chart.Dependency) error { } if _, ok := churls[churl]; ok { - fmt.Fprintf(m.Out, "Already downloaded %s from repo %s\n", dep.Name, dep.Repository) + _, err := fmt.Fprintf(m.Out, "Already downloaded %s from repo %s\n", dep.Name, dep.Repository) + if err != nil { + return err + } continue } - fmt.Fprintf(m.Out, "Downloading %s from repo %s\n", dep.Name, dep.Repository) + _, err = fmt.Fprintf(m.Out, "Downloading %s from repo %s\n", dep.Name, dep.Repository) + if err != nil { + return err + } dl := ChartDownloader{ Out: m.Out, @@ -371,7 +386,10 @@ func (m *Manager) downloadAll(deps []*chart.Dependency) error { return err } } else { - fmt.Fprintln(m.Out, "Save error occurred: ", saveError) + _, err := fmt.Fprintln(m.Out, "Save error occurred: ", saveError) + if err != nil { + return err + } return saveError } return nil @@ -428,24 +446,33 @@ func (m *Manager) safeMoveDeps(deps []*chart.Dependency, source, dest string) er destfile := filepath.Join(dest, filename) existsInSourceDirectory[filename] = true if _, err := loader.LoadFile(sourcefile); err != nil { - fmt.Fprintf(m.Out, "Could not verify %s for moving: %s (Skipping)", sourcefile, err) + _, err := fmt.Fprintf(m.Out, "Could not verify %s for moving: %s (Skipping)", sourcefile, err) + if err != nil { + return err + } continue } // NOTE: no need to delete the dest; os.Rename replaces it. if err := fs.RenameWithFallback(sourcefile, destfile); err != nil { - fmt.Fprintf(m.Out, "Unable to move %s to charts dir %s (Skipping)", sourcefile, err) + _, err := fmt.Fprintf(m.Out, "Unable to move %s to charts dir %s (Skipping)", sourcefile, err) + if err != nil { + return err + } continue } } - fmt.Fprintln(m.Out, "Deleting outdated charts") + _, _ = fmt.Fprintln(m.Out, "Deleting outdated charts") // find all files that exist in dest that do not exist in source; delete them (outdated dependencies) for _, file := range destFiles { if !file.IsDir() && !existsInSourceDirectory[file.Name()] { fname := filepath.Join(dest, file.Name()) ch, err := loader.LoadFile(fname) if err != nil { - fmt.Fprintf(m.Out, "Could not verify %s for deletion: %s (Skipping)\n", fname, err) + _, err := fmt.Fprintf(m.Out, "Could not verify %s for deletion: %s (Skipping)\n", fname, err) + if err != nil { + return err + } continue } // local dependency - skip @@ -453,7 +480,10 @@ func (m *Manager) safeMoveDeps(deps []*chart.Dependency, source, dest string) er continue } if err := os.Remove(fname); err != nil { - fmt.Fprintf(m.Out, "Could not delete %s: %s (Skipping)", fname, err) + _, err := fmt.Fprintf(m.Out, "Could not delete %s: %s (Skipping)", fname, err) + if err != nil { + return err + } continue } } @@ -549,7 +579,7 @@ func (m *Manager) ensureMissingRepos(repoNames map[string]string, deps []*chart. // the dependencies that are not known to the user if update skipping // is not configured. if !m.SkipUpdate && len(ru) > 0 { - fmt.Fprintln(m.Out, "Getting updates for unmanaged Helm repositories...") + _, _ = fmt.Fprintln(m.Out, "Getting updates for unmanaged Helm repositories...") if err := m.parallelRepoUpdate(ru); err != nil { return repoNames, err } @@ -587,7 +617,10 @@ func (m *Manager) resolveRepoNames(deps []*chart.Dependency) (map[string]string, } if m.Debug { - fmt.Fprintf(m.Out, "Repository from local path: %s\n", dd.Repository) + _, err := fmt.Fprintf(m.Out, "Repository from local path: %s\n", dd.Repository) + if err != nil { + return nil, err + } } reposMap[dd.Name] = dd.Repository continue @@ -653,12 +686,12 @@ func (m *Manager) UpdateRepositories() error { } repos := rf.Repositories if len(repos) > 0 { - fmt.Fprintln(m.Out, "Hang tight while we grab the latest from your chart repositories...") + _, _ = fmt.Fprintln(m.Out, "Hang tight while we grab the latest from your chart repositories...") // This prints warnings straight to out. if err := m.parallelRepoUpdate(repos); err != nil { return err } - fmt.Fprintln(m.Out, "Update Complete. ⎈Happy Helming!⎈") + _, _ = fmt.Fprintln(m.Out, "Update Complete. ⎈Happy Helming!⎈") } return nil } @@ -696,17 +729,17 @@ func (m *Manager) parallelRepoUpdate(repos []*repo.Entry) error { // For those dependencies that are not known to helm and using a // generated key name we display the repo url. if strings.HasPrefix(r.Config.Name, managerKeyPrefix) { - fmt.Fprintf(m.Out, "...Unable to get an update from the %q chart repository:\n\t%s\n", r.Config.URL, err) + _, _ = fmt.Fprintf(m.Out, "...Unable to get an update from the %q chart repository:\n\t%s\n", r.Config.URL, err) } else { - fmt.Fprintf(m.Out, "...Unable to get an update from the %q chart repository (%s):\n\t%s\n", r.Config.Name, r.Config.URL, err) + _, _ = fmt.Fprintf(m.Out, "...Unable to get an update from the %q chart repository (%s):\n\t%s\n", r.Config.Name, r.Config.URL, err) } } else { // For those dependencies that are not known to helm and using a // generated key name we display the repo url. if strings.HasPrefix(r.Config.Name, managerKeyPrefix) { - fmt.Fprintf(m.Out, "...Successfully got an update from the %q chart repository\n", r.Config.URL) + _, _ = fmt.Fprintf(m.Out, "...Successfully got an update from the %q chart repository\n", r.Config.URL) } else { - fmt.Fprintf(m.Out, "...Successfully got an update from the %q chart repository\n", r.Config.Name) + _, _ = fmt.Fprintf(m.Out, "...Successfully got an update from the %q chart repository\n", r.Config.Name) } } wg.Done() diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go index 7c858690f..795152ff9 100644 --- a/pkg/engine/engine.go +++ b/pkg/engine/engine.go @@ -350,13 +350,22 @@ type TraceableError struct { func (t TraceableError) String() string { var errorString strings.Builder if t.location != "" { - fmt.Fprintf(&errorString, "%s\n ", t.location) + _, err := fmt.Fprintf(&errorString, "%s\n ", t.location) + if err != nil { + return "" + } } if t.executedFunction != "" { - fmt.Fprintf(&errorString, "%s\n ", t.executedFunction) + _, err := fmt.Fprintf(&errorString, "%s\n ", t.executedFunction) + if err != nil { + return "" + } } if t.message != "" { - fmt.Fprintf(&errorString, "%s\n", t.message) + _, err := fmt.Fprintf(&errorString, "%s\n", t.message) + if err != nil { + return "" + } } return errorString.String() } @@ -422,7 +431,10 @@ func reformatExecErrorMsg(filename string, err error) error { var finalErrorString strings.Builder for _, fileLocation := range fileLocations { - fmt.Fprintf(&finalErrorString, "%s", fileLocation.String()) + _, err := fmt.Fprintf(&finalErrorString, "%s", fileLocation.String()) + if err != nil { + return err + } } return errors.New(strings.TrimSpace(finalErrorString.String())) diff --git a/pkg/kube/client.go b/pkg/kube/client.go index 26ba7abfc..700a4011a 100644 --- a/pkg/kube/client.go +++ b/pkg/kube/client.go @@ -335,7 +335,10 @@ func (c *Client) Get(resources ResourceList, related bool) (map[string][]runtime vk := gvk.Version + "/" + gvk.Kind obj, err := getResource(info) if err != nil { - fmt.Fprintf(buf, "Get resource %s failed, err:%v\n", info.Name, err) + _, err := fmt.Fprintf(buf, "Get resource %s failed, err:%v\n", info.Name, err) + if err != nil { + return err + } } else { objs[vk] = append(objs[vk], obj) diff --git a/pkg/registry/client.go b/pkg/registry/client.go index 95250f8da..9b651cbc5 100644 --- a/pkg/registry/client.go +++ b/pkg/registry/client.go @@ -258,7 +258,7 @@ func (c *Client) Login(host string, options ...LoginOption) error { return err } - fmt.Fprintln(c.out, "Login Succeeded") + _, _ = fmt.Fprintln(c.out, "Login Succeeded") return nil } @@ -529,12 +529,24 @@ func (c *Client) processChartPull(genericResult *GenericPullResult, operation *p result.Prov.Size = provDescriptor.Size } - fmt.Fprintf(c.out, "Pulled: %s\n", result.Ref) - fmt.Fprintf(c.out, "Digest: %s\n", result.Manifest.Digest) + _, err = fmt.Fprintf(c.out, "Pulled: %s\n", result.Ref) + if err != nil { + return nil, err + } + _, err = fmt.Fprintf(c.out, "Digest: %s\n", result.Manifest.Digest) + if err != nil { + return nil, err + } if strings.Contains(result.Ref, "_") { - fmt.Fprintf(c.out, "%s contains an underscore.\n", result.Ref) - fmt.Fprint(c.out, registryUnderscoreMessage+"\n") + _, err := fmt.Fprintf(c.out, "%s contains an underscore.\n", result.Ref) + if err != nil { + return nil, err + } + _, err = fmt.Fprint(c.out, registryUnderscoreMessage+"\n") + if err != nil { + return nil, err + } } return result, nil @@ -731,11 +743,23 @@ func (c *Client) Push(data []byte, ref string, options ...PushOption) (*PushResu Size: provDescriptor.Size, } } - fmt.Fprintf(c.out, "Pushed: %s\n", result.Ref) - fmt.Fprintf(c.out, "Digest: %s\n", result.Manifest.Digest) + _, err = fmt.Fprintf(c.out, "Pushed: %s\n", result.Ref) + if err != nil { + return nil, err + } + _, err = fmt.Fprintf(c.out, "Digest: %s\n", result.Manifest.Digest) + if err != nil { + return nil, err + } if strings.Contains(parsedRef.orasReference.Reference, "_") { - fmt.Fprintf(c.out, "%s contains an underscore.\n", result.Ref) - fmt.Fprint(c.out, registryUnderscoreMessage+"\n") + _, err := fmt.Fprintf(c.out, "%s contains an underscore.\n", result.Ref) + if err != nil { + return nil, err + } + _, err = fmt.Fprint(c.out, registryUnderscoreMessage+"\n") + if err != nil { + return nil, err + } } return result, err diff --git a/pkg/registry/plugin.go b/pkg/registry/plugin.go index 991bace76..eb7f858e2 100644 --- a/pkg/registry/plugin.go +++ b/pkg/registry/plugin.go @@ -147,15 +147,30 @@ func (c *Client) processPluginPull(genericResult *GenericPullResult, pluginName } } - fmt.Fprintf(c.out, "Pulled plugin: %s\n", result.Ref) - fmt.Fprintf(c.out, "Digest: %s\n", result.Manifest.Digest) + _, err = fmt.Fprintf(c.out, "Pulled plugin: %s\n", result.Ref) + if err != nil { + return nil, err + } + _, err = fmt.Fprintf(c.out, "Digest: %s\n", result.Manifest.Digest) + if err != nil { + return nil, err + } if result.Prov.Data != nil { - fmt.Fprintf(c.out, "Provenance: %s\n", foundProvenanceName) + _, err := fmt.Fprintf(c.out, "Provenance: %s\n", foundProvenanceName) + if err != nil { + return nil, err + } } if strings.Contains(result.Ref, "_") { - fmt.Fprintf(c.out, "%s contains an underscore.\n", result.Ref) - fmt.Fprint(c.out, registryUnderscoreMessage+"\n") + _, err := fmt.Fprintf(c.out, "%s contains an underscore.\n", result.Ref) + if err != nil { + return nil, err + } + _, err = fmt.Fprint(c.out, registryUnderscoreMessage+"\n") + if err != nil { + return nil, err + } } return result, nil diff --git a/pkg/repo/v1/chartrepo.go b/pkg/repo/v1/chartrepo.go index 95c04ccef..17fadb996 100644 --- a/pkg/repo/v1/chartrepo.go +++ b/pkg/repo/v1/chartrepo.go @@ -104,7 +104,10 @@ func (r *ChartRepository) DownloadIndexFile() (string, error) { // Create the chart list file in the cache directory var charts strings.Builder for name := range indexFile.Entries { - fmt.Fprintln(&charts, name) + _, err := fmt.Fprintln(&charts, name) + if err != nil { + return "", err + } } chartsFile := filepath.Join(r.CachePath, helmpath.CacheChartsFile(r.Config.Name)) os.MkdirAll(filepath.Dir(chartsFile), 0755)