From e62421055a6127bdf72c62ffd539aae4120b4a8a Mon Sep 17 00:00:00 2001 From: Gagan Gupta Date: Sun, 8 Mar 2026 13:15:07 +0530 Subject: [PATCH 1/2] fix: make toToml swallow errors consistent with toYaml and toJson Previously toToml returned err.Error() on failure, rendering the error message string into the template output. toYAML and toJSON both return an empty string on error to swallow it silently inside templates. This aligns toToml behavior with the other serialization functions. Fixes: https://github.com/helm/helm/issues/31430 Signed-off-by: Gagan Gupta --- pkg/engine/funcs.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/engine/funcs.go b/pkg/engine/funcs.go index ba842a51a..4ff8f5dd0 100644 --- a/pkg/engine/funcs.go +++ b/pkg/engine/funcs.go @@ -150,6 +150,7 @@ func fromYAMLArray(str string) []any { // toTOML takes an interface, marshals it to toml, and returns a string. It will // always return a string, even on marshal error (empty string). +// Errors are swallowed, consistent with toYAML and toJSON behavior. // // This is designed to be called from a template. func toTOML(v any) string { @@ -157,7 +158,8 @@ func toTOML(v any) string { e := toml.NewEncoder(b) err := e.Encode(v) if err != nil { - return err.Error() + // Swallow errors inside of a template. + return "" } return b.String() } From 68097e36105adeee5979053d72ef892a74507c9f Mon Sep 17 00:00:00 2001 From: Gagan Gupta Date: Sun, 8 Mar 2026 15:13:27 +0530 Subject: [PATCH 2/2] test: add test case for toToml error swallowing Add a test case that verifies toToml returns "" on encoding errors (e.g. map[int]string where keys are not strings), consistent with how toYaml and toJson handle errors. Signed-off-by: Gagan Gupta --- pkg/engine/funcs_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/engine/funcs_test.go b/pkg/engine/funcs_test.go index 48202454e..362aeabfd 100644 --- a/pkg/engine/funcs_test.go +++ b/pkg/engine/funcs_test.go @@ -122,6 +122,12 @@ keyInElement1 = "valueInElement1"`, tpl: `{{ fromYamlArray . }}`, expect: `[error unmarshaling JSON: while decoding JSON: json: cannot unmarshal object into Go value of type []interface {}]`, vars: `hello: world`, + }, { + // toToml should swallow errors and return "" like toYaml and toJson do. + // map[int]string cannot be encoded as TOML (keys must be strings). + tpl: `{{ toToml . }}`, + expect: ``, + vars: map[int]string{1: "one"}, }, { // This should never result in a network lookup. Regression for #7955 tpl: `{{ lookup "v1" "Namespace" "" "unlikelynamespace99999999" }}`,