Skip to content

fix: Improve error reporting for helm template --debug with --show-only - #31185

Merged
TerryHowe merged 4 commits into
helm:mainfrom
kyokuping:fix/31183
Jun 14, 2026
Merged

fix: Improve error reporting for helm template --debug with --show-only#31185
TerryHowe merged 4 commits into
helm:mainfrom
kyokuping:fix/31183

Conversation

@kyokuping

Copy link
Copy Markdown
Contributor

closes #31183

What this PR does / why we need it:

This PR fixes a bug where helm template --debug --show-only would show a misleading "could not find template" error when the target template had a rendering error.
Currently, the --debug flag suppresses the initial template rendering error and then later reports the misleading error, which hides the true cause of the failure. This change ensures that the original rendering error is captured and prioritized, providing users with accurate and actionable feedback.

Special notes for your reviewer:
The core of the fix is in the error handling logic after the templates are rendered. I've introduced a change to preserve the error from the runInstall() function, even in debug mode. The final error report now checks for this rendering error first before checking if the file specified in --show-only exists in the manifest output.

If applicable:

  • this PR contains user facing changes (the docs needed label should be applied if so)
  • this PR contains unit tests
  • this PR has been tested for backwards compatibility

@pull-request-size pull-request-size Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Aug 26, 2025
Comment thread pkg/cmd/template.go Outdated
}
if missing {
return fmt.Errorf("could not find template %s in chart", f)
if err != nil && settings.Debug {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would probably clearer and more reliable if you saved the error above like saveError := err and then no need to check settings.Debug. I get this works now, but someone might come along and not realize that err gets used way down here later.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@kyokuping
kyokuping force-pushed the fix/31183 branch 2 times, most recently from 489a06e to da7a429 Compare August 27, 2025 11:48
@kyokuping
kyokuping requested a review from TerryHowe August 27, 2025 11:48

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

Thanks!

@TerryHowe TerryHowe closed this Dec 13, 2025
@TerryHowe TerryHowe reopened this Dec 13, 2025
@TerryHowe TerryHowe added the Has One Approval This PR has one approval. It still needs a second approval to be merged. label Dec 13, 2025
@victoravt

Copy link
Copy Markdown

Hey, waiting for this 🫡

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the lint error.

Copilot AI review requested due to automatic review settings March 8, 2026 13:05
@kyokuping
kyokuping requested a review from TerryHowe March 8, 2026 13:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes misleading error reporting for helm template --debug --show-only by preserving and prioritizing the original render/install error over the downstream “could not find template” message when rendering fails (closes #31183).

Changes:

  • Preserve the original runInstall() error in template command flow and return it when --show-only cannot find rendered output due to a render failure.
  • Add a new regression test case for --debug --show-only when the targeted template has an invalid template expression.
  • Introduce a dedicated test chart and golden output capturing the corrected error behavior.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/cmd/template.go Preserve runInstall() error and prefer it over misleading --show-only missing-template error in debug render-failure scenarios.
pkg/cmd/template_test.go Add regression test for template --debug --show-only when template rendering fails.
pkg/cmd/testdata/testcharts/chart-with-template-with-invalid-template-expr/Chart.yaml New test chart metadata for invalid template expression scenario.
pkg/cmd/testdata/testcharts/chart-with-template-with-invalid-template-expr/README.md New test chart readme (mirrors existing testchart structure).
pkg/cmd/testdata/testcharts/chart-with-template-with-invalid-template-expr/templates/alpine-pod.yaml New template designed to trigger a render-time template execution error.
pkg/cmd/testdata/testcharts/chart-with-template-with-invalid-template-expr/values.yaml Values for the new test chart.
pkg/cmd/testdata/output/template-with-invalid-template-expr-debug-show-only.txt New golden file asserting corrected error output for the regression case.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/cmd/template.go Outdated
Comment on lines +191 to +193
if savedErr != nil && settings.Debug {
// assume the manifest itself is too malformed to be rendered
return savedErr

Copilot AI Mar 8, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inline comment about the savedErr branch is misleading: the code isn’t detecting a “malformed manifest”, it’s prioritizing the original render/install error over a potentially misleading --show-only “could not find template” error (because the file list is derived from rendered output). Consider rewording the comment to reflect that rationale so future readers don’t think there’s a manifest-structure check here.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree with the above

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/cmd/template.go
Copilot AI review requested due to automatic review settings May 4, 2026 02:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings May 4, 2026 02:37
@kyokuping

Copy link
Copy Markdown
Contributor Author

@TerryHowe Could you please approve the CI run so we can proceed with merging?

@kyokuping
kyokuping requested a review from gjenkins8 May 12, 2026 09:19
Comment thread pkg/cmd/template.go Outdated
}
return err
}
savedErr := err

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
savedErr := err
installErr := err

@gjenkins8 gjenkins8 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

…ow-only`

Signed-off-by: Jeaeun Kim <me@kyoku.dev>
Signed-off-by: Jeaeun Kim <me@kyoku.dev>
Signed-off-by: Jeaeun Kim <me@kyoku.dev>
Signed-off-by: Jeaeun Kim <me@kyoku.dev>
Copilot AI review requested due to automatic review settings June 13, 2026 03:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

@@ -0,0 +1,8 @@
apiVersion: v1
sources:
- https://github.com/helm/helm
version: 0.1.0
type: application
@@ -0,0 +1,13 @@
#Alpine: A simple Helm chart
The `values.yaml` file contains the default values for the
`alpine-pod.yaml` template.

You can install this example using `helm install ./alpine`.
Comment thread pkg/cmd/template.go
Comment on lines 190 to +194
if missing {
if installErr != nil && settings.Debug {
// assume the manifest itself is too malformed to be rendered
return installErr
}
@kyokuping
kyokuping requested review from TerryHowe and Copilot June 13, 2026 03:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

@@ -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 `values.yaml` file contains the default values for the
`alpine-pod.yaml` template.

You can install this example using `helm install ./alpine`.
Comment thread pkg/cmd/template.go
}
return err
}
installErr := err

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@TerryHowe
TerryHowe merged commit f8b5203 into helm:main Jun 14, 2026
5 checks passed
@scottrigby scottrigby added bug Categorizes issue or PR as related to a bug. and removed Has One Approval This PR has one approval. It still needs a second approval to be merged. labels Aug 12, 2026
@scottrigby scottrigby changed the title chore: Improve error reporting for helm template --debug with --show-only fix: Improve error reporting for helm template --debug with --show-only Aug 13, 2026
@scottrigby scottrigby added this to the 4.2.4 milestone Aug 13, 2026
@github-actions github-actions Bot added the v4.x Issues and Pull Requests related to the major version v4 label Aug 13, 2026
@scottrigby scottrigby added needs-pick Indicates that a PR needs to be cherry-picked into the next release candidate. picked Indicates that a PR has been cherry-picked into the next release candidate. and removed v4.x Issues and Pull Requests related to the major version v4 needs-pick Indicates that a PR needs to be cherry-picked into the next release candidate. labels Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Categorizes issue or PR as related to a bug. picked Indicates that a PR has been cherry-picked into the next release candidate. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: helm template --debug fails with "could not find template" when --show-only targets a template with a rendering error.

6 participants