fix: handle errors in template engine and release storage

pkg/engine/engine.go:
- Return early when NewAccessor fails on main chart to avoid nil
  pointer panic on subsequent MetadataAsMap() call (line 541)
- Handle NewAccessor error on child dependencies instead of silently
  discarding it (resolves TODO on line 562)

pkg/storage/storage.go:
- Replace panic() calls in ListUninstalled and ListDeployed filter
  functions with Warn + return false, so a single corrupted release
  does not crash the entire list operation

Signed-off-by: Adesh Deshmukh <adeshkd123@gmail.com>
pull/32346/head
Adesh Deshmukh 3 weeks ago
parent 68977ec0b5
commit 25ce769be5

@ -563,6 +563,7 @@ func recAllTpls(c ci.Charter, templates map[string]renderable, values common.Val
accessor, err := ci.NewAccessor(c)
if err != nil {
slog.Error("error accessing chart", "error", err)
return nil
}
chartMetaData := accessor.MetadataAsMap()
chartMetaData["IsRoot"] = accessor.IsRoot()
@ -585,8 +586,11 @@ func recAllTpls(c ci.Charter, templates map[string]renderable, values common.Val
}
for _, child := range accessor.Dependencies() {
// TODO: Handle error
sub, _ := ci.NewAccessor(child)
sub, err := ci.NewAccessor(child)
if err != nil {
slog.Error("error accessing dependency", "dependency", child, "error", err)
continue
}
subCharts[sub.Name()] = recAllTpls(child, templates, next)
}

@ -126,10 +126,8 @@ func (s *Storage) ListUninstalled() ([]release.Releaser, error) {
return s.List(func(rls release.Releaser) bool {
rel, err := releaserToV1Release(rls)
if err != nil {
// This will only happen if calling code does not pass the proper types. This is
// a problem with the application and not user data.
s.Logger().Error("unable to convert release to typed release", slog.Any("error", err))
panic(fmt.Sprintf("unable to convert release to typed release: %s", err))
s.Logger().Warn("unable to convert release, skipping", slog.Any("error", err))
return false
}
return relutil.StatusFilter(common.StatusUninstalled).Check(rel)
})
@ -142,10 +140,8 @@ func (s *Storage) ListDeployed() ([]release.Releaser, error) {
return s.List(func(rls release.Releaser) bool {
rel, err := releaserToV1Release(rls)
if err != nil {
// This will only happen if calling code does not pass the proper types. This is
// a problem with the application and not user data.
s.Logger().Error("unable to convert release to typed release", slog.Any("error", err))
panic(fmt.Sprintf("unable to convert release to typed release: %s", err))
s.Logger().Warn("unable to convert release, skipping", slog.Any("error", err))
return false
}
return relutil.StatusFilter(common.StatusDeployed).Check(rel)
})

Loading…
Cancel
Save