diff --git a/pkg/helm/helm.go b/pkg/helm/helm.go index 152c7023..fe9801a6 100644 --- a/pkg/helm/helm.go +++ b/pkg/helm/helm.go @@ -265,12 +265,13 @@ func templateCommand(chart, repository, version, valuesFilePath, kubeVersion, ta func parseChartContents(chartContents string) ([]map[string]any, error) { var resources []map[string]any - for _, resource := range strings.Split(chartContents, "---") { + for _, resource := range strings.Split(chartContents, "---\n") { if resource == "" { continue } - if !strings.HasPrefix(strings.TrimSpace(resource), "# Source") { + resource = strings.TrimSpace(resource) + if !strings.HasPrefix(resource, "# Source") { continue } diff --git a/pkg/helm/helm_test.go b/pkg/helm/helm_test.go index 94554975..3ed6bd98 100644 --- a/pkg/helm/helm_test.go +++ b/pkg/helm/helm_test.go @@ -559,14 +559,15 @@ func TestTemplateCommand(t *testing.T) { func TestParseChartContents_InvalidPayload(t *testing.T) { contents := `--- -# Source +# Source: some-invalid.yaml invalid-resource ` resources, err := parseChartContents(contents) require.Error(t, err) - assert.ErrorContains(t, err, "yaml: unmarshal errors:\n line 2: cannot unmarshal !!str `invalid...` into map[string]interface {}") + assert.ErrorContains(t, err, "decoding resource from source '# Source: some-invalid.yaml'") + assert.ErrorContains(t, err, "yaml: unmarshal errors:\n line 1: cannot unmarshal !!str `invalid...` into map[string]interface {}") assert.Nil(t, resources) }