Fixed error reporting when included invalid files in include section

This commit is contained in:
Andrew Nester 2023-07-04 11:17:00 +02:00
parent 335475095e
commit 6d6b689623
No known key found for this signature in database
GPG Key ID: 12BC628A44B7DA57
3 changed files with 19 additions and 1 deletions

View File

@ -49,6 +49,10 @@ func (m *processRootIncludes) Apply(ctx context.Context, b *bundle.Bundle) error
return err
}
if len(matches) == 0 {
return fmt.Errorf("%s defined in 'include' section does not match any files", entry)
}
// Filter matches to ones we haven't seen yet.
var includes []string
for _, match := range matches {

View File

@ -108,3 +108,17 @@ func TestProcessRootIncludesRemoveDups(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, []string{"a.yml"}, bundle.Config.Include)
}
func TestProcessRootIncludesNotExists(t *testing.T) {
bundle := &bundle.Bundle{
Config: config.Root{
Path: t.TempDir(),
Include: []string{
"notexist.yml",
},
},
}
err := mutator.ProcessRootIncludes().Apply(context.Background(), bundle)
require.Error(t, err)
assert.Contains(t, err.Error(), "notexist.yml defined in 'include' section does not match any files")
}

View File

@ -118,7 +118,7 @@ func (r *Root) Load(path string) error {
}
err = yaml.Unmarshal(raw, r)
if err != nil {
return err
return fmt.Errorf("failed to load %s: %w", path, err)
}
r.Path = filepath.Dir(path)