From eb32b6166ec7cbd5ba6098f546db85ffbd33fbb1 Mon Sep 17 00:00:00 2001 From: yxxhero <11087727+yxxhero@users.noreply.github.com> Date: Tue, 8 Apr 2025 21:28:54 +0800 Subject: [PATCH] fix(state): enhance error message for missing .gotmpl extension in helmfile v1 (#1989) * fix(state): enhance error message for missing .gotmpl extension in helmfile Signed-off-by: yxxhero --- pkg/app/app_template_test.go | 4 ++-- pkg/state/create.go | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/app/app_template_test.go b/pkg/app/app_template_test.go index a29b1fea..e42122e1 100644 --- a/pkg/app/app_template_test.go +++ b/pkg/app/app_template_test.go @@ -414,7 +414,7 @@ releases: t.Run("fail due to unknown field with goccy/go-yaml", func(t *testing.T) { check(t, testcase{ goccyGoYaml: true, - error: `in ./helmfile.yaml: failed to read helmfile.yaml: reading document at index 1: [4:3] unknown field "foobar" + error: `in ./helmfile.yaml: failed to read helmfile.yaml: reading document at index 1. Started seeing this since Helmfile v1? Add the .gotmpl file extension: [4:3] unknown field "foobar" 2 | releases: 3 | - name: app1 > 4 | foobar: FOOBAR @@ -426,7 +426,7 @@ releases: t.Run("fail due to unknown field with gopkg.in/yaml.v2", func(t *testing.T) { check(t, testcase{ goccyGoYaml: false, - error: `in ./helmfile.yaml: failed to read helmfile.yaml: reading document at index 1: yaml: unmarshal errors: + error: `in ./helmfile.yaml: failed to read helmfile.yaml: reading document at index 1. Started seeing this since Helmfile v1? Add the .gotmpl file extension: yaml: unmarshal errors: line 4: field foobar not found in type state.ReleaseSpec`, }) }) diff --git a/pkg/state/create.go b/pkg/state/create.go index 9ca5d2e1..b175faf9 100644 --- a/pkg/state/create.go +++ b/pkg/state/create.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "io" + "path/filepath" "slices" "strings" @@ -109,6 +110,9 @@ func (c *StateCreator) Parse(content []byte, baseDir, file string) (*HelmState, if err == io.EOF { break } else if err != nil { + if filepath.Ext(file) != ".gotmpl" { + return nil, &StateLoadError{fmt.Sprintf("failed to read %s: reading document at index %d. Started seeing this since Helmfile v1? Add the .gotmpl file extension", file, i), err} + } return nil, &StateLoadError{fmt.Sprintf("failed to read %s: reading document at index %d", file, i), err} }