move saveError to collect all errors

rather than returning the latest error, collect all the errors that
happen while downloading/unarchiving and return them

Signed-off-by: Andrea Tartaglia <me@andreatartaglia.com>
pull/30616/head
Andrea Tartaglia 2 months ago
parent 62278a6c7b
commit c84208b883
No known key found for this signature in database

@ -269,7 +269,7 @@ func (m *Manager) downloadAll(deps []*chart.Dependency) error {
defer os.RemoveAll(tmpPath) defer os.RemoveAll(tmpPath)
fmt.Fprintf(m.Out, "Saving %d charts\n", len(deps)) fmt.Fprintf(m.Out, "Saving %d charts\n", len(deps))
var saveError error var saveErrors []error
churls := make(map[string]struct{}) churls := make(map[string]struct{})
for _, dep := range deps { for _, dep := range deps {
// No repository means the chart is in charts directory // No repository means the chart is in charts directory
@ -293,7 +293,7 @@ func (m *Manager) downloadAll(deps []*chart.Dependency) error {
} }
if !constraint.Check(v) { if !constraint.Check(v) {
saveError = fmt.Errorf("dependency %s at version %s does not satisfy the constraint %s", dep.Name, ch.Metadata.Version, dep.Version) saveErrors = append(saveErrors, fmt.Errorf("dependency %s at version %s does not satisfy the constraint %s", dep.Name, ch.Metadata.Version, dep.Version))
break break
} }
continue continue
@ -304,7 +304,7 @@ func (m *Manager) downloadAll(deps []*chart.Dependency) error {
} }
ver, err := tarFromLocalDir(m.ChartPath, dep.Name, dep.Repository, dep.Version, tmpPath) ver, err := tarFromLocalDir(m.ChartPath, dep.Name, dep.Repository, dep.Version, tmpPath)
if err != nil { if err != nil {
saveError = err saveErrors = append(saveErrors, err)
break break
} }
dep.Version = ver dep.Version = ver
@ -315,7 +315,7 @@ func (m *Manager) downloadAll(deps []*chart.Dependency) error {
// https://github.com/helm/helm/issues/1439 // https://github.com/helm/helm/issues/1439
churl, username, password, insecureskiptlsverify, passcredentialsall, caFile, certFile, keyFile, err := m.findChartURL(dep.Name, dep.Version, dep.Repository, repos) churl, username, password, insecureskiptlsverify, passcredentialsall, caFile, certFile, keyFile, err := m.findChartURL(dep.Name, dep.Version, dep.Repository, repos)
if err != nil { if err != nil {
saveError = fmt.Errorf("could not find %s: %w", churl, err) saveErrors = append(saveErrors, fmt.Errorf("could not find %s: %w", churl, err))
break break
} }
@ -355,7 +355,7 @@ func (m *Manager) downloadAll(deps []*chart.Dependency) error {
_, v, err := dl.DownloadTo(churl, version, tmpPath) _, v, err := dl.DownloadTo(churl, version, tmpPath)
if err != nil { if err != nil {
saveError = fmt.Errorf("could not download %s: %w", churl, err) saveErrors = append(saveErrors, fmt.Errorf("could not download %s: %w", churl, err))
break break
} }
@ -374,15 +374,14 @@ func (m *Manager) downloadAll(deps []*chart.Dependency) error {
churls[churl] = struct{}{} churls[churl] = struct{}{}
} }
// TODO: this should probably be refactored to be a []error, so we can capture and provide more information rather than "last error wins". if saveErrors == nil {
if saveError == nil {
// now we can move all downloaded charts to destPath and delete outdated dependencies // now we can move all downloaded charts to destPath and delete outdated dependencies
if err := m.safeMoveDeps(deps, tmpPath, destPath); err != nil { if err := m.safeMoveDeps(deps, tmpPath, destPath); err != nil {
return err return err
} }
} else { } else {
fmt.Fprintln(m.Out, "Save error occurred: ", saveError) fmt.Fprintln(m.Out, "Save error occurred: ", saveErrors)
return saveError return errors.Join(saveErrors...)
} }
return nil return nil
} }

Loading…
Cancel
Save