adding in error handling for fmt.Fprintln

Signed-off-by: Robert Sirchia <rsirchia@outlook.com>
pull/31300/head
Robert Sirchia 1 week ago
parent ff61915cda
commit 6373f1ae91
No known key found for this signature in database
GPG Key ID: C2D40F4D8196E874

@ -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

@ -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)
}
}
}

@ -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
}

@ -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.

@ -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))
}
}
}

@ -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

@ -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
}

@ -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
}

@ -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]])
}
},
}

@ -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
},

@ -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
},
}

@ -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
},

@ -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)
}

@ -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()
}()

@ -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
},

@ -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
}

@ -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
},

@ -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
}

@ -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
},
}

@ -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
}

@ -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))

@ -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))

@ -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

@ -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
},

@ -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
},
}

@ -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
}

@ -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
}

@ -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

@ -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
}

@ -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
},
}

@ -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,

@ -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
},
}

@ -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
}
}
}

@ -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
},

@ -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{

@ -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
},

@ -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
}

@ -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
}

@ -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()

@ -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()))

@ -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)

@ -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

@ -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

@ -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)

Loading…
Cancel
Save