From 078b7aa0470d7cc713fd87cf2cad24090ee45939 Mon Sep 17 00:00:00 2001 From: Jeaeun Kim Date: Tue, 26 Aug 2025 13:07:00 +0900 Subject: [PATCH 1/5] chore: Improve error reporting for `helm template --debug` with `--show-only` Signed-off-by: Jeaeun Kim Signed-off-by: kyokuping --- pkg/cmd/template.go | 7 ++++++- pkg/cmd/template_test.go | 6 ++++++ ...e-with-invalid-template-expr-debug-show-only.txt | 3 +++ .../Chart.yaml | 8 ++++++++ .../README.md | 13 +++++++++++++ .../templates/alpine-pod.yaml | 9 +++++++++ .../values.yaml | 1 + 7 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 pkg/cmd/testdata/output/template-with-invalid-template-expr-debug-show-only.txt create mode 100644 pkg/cmd/testdata/testcharts/chart-with-template-with-invalid-template-expr/Chart.yaml create mode 100644 pkg/cmd/testdata/testcharts/chart-with-template-with-invalid-template-expr/README.md create mode 100644 pkg/cmd/testdata/testcharts/chart-with-template-with-invalid-template-expr/templates/alpine-pod.yaml create mode 100644 pkg/cmd/testdata/testcharts/chart-with-template-with-invalid-template-expr/values.yaml diff --git a/pkg/cmd/template.go b/pkg/cmd/template.go index 047fd60df..480fe7ed4 100644 --- a/pkg/cmd/template.go +++ b/pkg/cmd/template.go @@ -187,7 +187,12 @@ func newTemplateCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { missing = false } if missing { - return fmt.Errorf("could not find template %s in chart", f) + if err != nil && settings.Debug { + // assume the manifest itself is too malformed to be rendered + return err + } else { + return fmt.Errorf("could not find template %s in chart", f) + } } } for _, m := range manifestsToRender { diff --git a/pkg/cmd/template_test.go b/pkg/cmd/template_test.go index 7391781f6..b43151413 100644 --- a/pkg/cmd/template_test.go +++ b/pkg/cmd/template_test.go @@ -133,6 +133,12 @@ func TestTemplateCmd(t *testing.T) { wantError: true, golden: "output/template-with-invalid-yaml-debug.txt", }, + { + name: "chart with template with invalid template expression (--debug, --show-only)", + cmd: fmt.Sprintf("template '%s' --debug --show-only %s", "testdata/testcharts/chart-with-template-with-invalid-template-expr", "templates/alpine-pod.yaml"), + wantError: true, + golden: "output/template-with-invalid-template-expr-debug-show-only.txt", + }, { name: "template skip-tests", cmd: fmt.Sprintf(`template '%s' --skip-tests`, chartPath), diff --git a/pkg/cmd/testdata/output/template-with-invalid-template-expr-debug-show-only.txt b/pkg/cmd/testdata/output/template-with-invalid-template-expr-debug-show-only.txt new file mode 100644 index 000000000..89d518bbb --- /dev/null +++ b/pkg/cmd/testdata/output/template-with-invalid-template-expr-debug-show-only.txt @@ -0,0 +1,3 @@ +Error: chart-with-template-with-invalid-template-expr/templates/alpine-pod.yaml:7:38 + executing "chart-with-template-with-invalid-template-expr/templates/alpine-pod.yaml" at : + invalid value; expected string diff --git a/pkg/cmd/testdata/testcharts/chart-with-template-with-invalid-template-expr/Chart.yaml b/pkg/cmd/testdata/testcharts/chart-with-template-with-invalid-template-expr/Chart.yaml new file mode 100644 index 000000000..83541d4dd --- /dev/null +++ b/pkg/cmd/testdata/testcharts/chart-with-template-with-invalid-template-expr/Chart.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +description: Deploy a basic Alpine Linux pod +home: https://helm.sh/helm +name: chart-with-template-with-invalid-template-expr +sources: + - https://github.com/helm/helm +version: 0.1.0 +type: application diff --git a/pkg/cmd/testdata/testcharts/chart-with-template-with-invalid-template-expr/README.md b/pkg/cmd/testdata/testcharts/chart-with-template-with-invalid-template-expr/README.md new file mode 100644 index 000000000..fcf7ee017 --- /dev/null +++ b/pkg/cmd/testdata/testcharts/chart-with-template-with-invalid-template-expr/README.md @@ -0,0 +1,13 @@ +#Alpine: A simple Helm chart + +Run a single pod of Alpine Linux. + +This example was generated using the command `helm create alpine`. + +The `templates/` directory contains a very simple pod resource with a +couple of parameters. + +The `values.yaml` file contains the default values for the +`alpine-pod.yaml` template. + +You can install this example using `helm install ./alpine`. diff --git a/pkg/cmd/testdata/testcharts/chart-with-template-with-invalid-template-expr/templates/alpine-pod.yaml b/pkg/cmd/testdata/testcharts/chart-with-template-with-invalid-template-expr/templates/alpine-pod.yaml new file mode 100644 index 000000000..bdc0fe39b --- /dev/null +++ b/pkg/cmd/testdata/testcharts/chart-with-template-with-invalid-template-expr/templates/alpine-pod.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{.Release.Name}}-{{.Values.Name}}" +spec: + containers: + - name: {{ .Values.nonExistentKey | b64enc }} + image: "alpine:3.9" + command: ["/bin/sleep","9000"] diff --git a/pkg/cmd/testdata/testcharts/chart-with-template-with-invalid-template-expr/values.yaml b/pkg/cmd/testdata/testcharts/chart-with-template-with-invalid-template-expr/values.yaml new file mode 100644 index 000000000..807e12aea --- /dev/null +++ b/pkg/cmd/testdata/testcharts/chart-with-template-with-invalid-template-expr/values.yaml @@ -0,0 +1 @@ +Name: my-alpine From 1a5b625d10bfe05c2b10dd153c1af72d576be676 Mon Sep 17 00:00:00 2001 From: Jeaeun Kim Date: Wed, 27 Aug 2025 20:46:49 +0900 Subject: [PATCH 2/5] chore: store err separately for clarity Signed-off-by: Jeaeun Kim Signed-off-by: kyokuping --- pkg/cmd/template.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/cmd/template.go b/pkg/cmd/template.go index 480fe7ed4..929399f17 100644 --- a/pkg/cmd/template.go +++ b/pkg/cmd/template.go @@ -113,6 +113,7 @@ func newTemplateCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { } return err } + savedErr := err // We ignore a potential error here because, when the --debug flag was specified, // we always want to print the YAML, even if it is not valid. The error is still returned afterwards. @@ -187,9 +188,9 @@ func newTemplateCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { missing = false } if missing { - if err != nil && settings.Debug { + if savedErr != nil && settings.Debug { // assume the manifest itself is too malformed to be rendered - return err + return savedErr } else { return fmt.Errorf("could not find template %s in chart", f) } @@ -203,7 +204,7 @@ func newTemplateCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { } } - return err + return savedErr }, } From 9d5593f29d8f9dbf5410c81b7c25856f8a05502a Mon Sep 17 00:00:00 2001 From: kyokuping Date: Sun, 8 Mar 2026 22:05:31 +0900 Subject: [PATCH 3/5] chore: fix lint Signed-off-by: kyokuping --- pkg/cmd/template.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/cmd/template.go b/pkg/cmd/template.go index 929399f17..0c792977a 100644 --- a/pkg/cmd/template.go +++ b/pkg/cmd/template.go @@ -191,9 +191,8 @@ func newTemplateCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { if savedErr != nil && settings.Debug { // assume the manifest itself is too malformed to be rendered return savedErr - } else { - return fmt.Errorf("could not find template %s in chart", f) } + return fmt.Errorf("could not find template %s in chart", f) } } for _, m := range manifestsToRender { From c1a752ca8889e07cebca964080edb66f295c283f Mon Sep 17 00:00:00 2001 From: Jeaeun Kim <109906379+kyokuping@users.noreply.github.com> Date: Mon, 4 May 2026 11:22:45 +0900 Subject: [PATCH 4/5] chore: update comment Co-authored-by: Terry Howe Signed-off-by: Jeaeun Kim <109906379+kyokuping@users.noreply.github.com> --- pkg/cmd/template.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cmd/template.go b/pkg/cmd/template.go index 0c792977a..655a7354d 100644 --- a/pkg/cmd/template.go +++ b/pkg/cmd/template.go @@ -189,7 +189,7 @@ func newTemplateCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { } if missing { if savedErr != nil && settings.Debug { - // assume the manifest itself is too malformed to be rendered + // render error caused --show-only output to be empty; return the original error return savedErr } return fmt.Errorf("could not find template %s in chart", f) From 426460f89b160393a6cf30dcb827349c352ac580 Mon Sep 17 00:00:00 2001 From: Jeaeun Kim <109906379+kyokuping@users.noreply.github.com> Date: Mon, 4 May 2026 11:37:03 +0900 Subject: [PATCH 5/5] Chore: Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Jeaeun Kim <109906379+kyokuping@users.noreply.github.com> --- .../chart-with-template-with-invalid-template-expr/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cmd/testdata/testcharts/chart-with-template-with-invalid-template-expr/README.md b/pkg/cmd/testdata/testcharts/chart-with-template-with-invalid-template-expr/README.md index fcf7ee017..05d39dbbc 100644 --- a/pkg/cmd/testdata/testcharts/chart-with-template-with-invalid-template-expr/README.md +++ b/pkg/cmd/testdata/testcharts/chart-with-template-with-invalid-template-expr/README.md @@ -1,4 +1,4 @@ -#Alpine: A simple Helm chart +# Alpine: A simple Helm chart Run a single pod of Alpine Linux.