fix: preserve include directive in output on error in ProcessIncludes

All error paths in the ReplaceAllFunc callback returned nil, which
ReplaceAllFunc treats as an empty replacement, silently erasing the
guard (if err != nil) fired, every subsequent include in the file
was also erased. Return spec (the original directive bytes) instead
so failed includes are preserved and subsequent ones are not lost.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Manuel Rüger 2026-03-13 01:50:45 +01:00
parent 4c81c81fb3
commit fef39dc1e0

View File

@ -113,7 +113,7 @@ func ProcessIncludes(
contents,
func(spec []byte) []byte {
if err != nil {
return nil
return spec
}
groups := reIncludeDirective.FindSubmatch(spec)
@ -143,7 +143,7 @@ func ProcessIncludes(
"unable to unmarshal template data config",
)
return nil
return spec
}
log.Tracef(vardump(facts, data), "including template %q", path)
@ -151,7 +151,7 @@ func ProcessIncludes(
templates, err = LoadTemplate(base, includePath, path, left, right, templates)
if err != nil {
err = facts.Format(err, "unable to load template")
return nil
return spec
}
var buffer bytes.Buffer
@ -163,7 +163,7 @@ func ProcessIncludes(
"unable to execute template",
)
return nil
return spec
}
recurse = true