From 4c81c81fb3238df2ed989e3b387e96612eccfd8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20R=C3=BCger?= Date: Fri, 13 Mar 2026 01:50:45 +0100 Subject: [PATCH] fix: return original match on error in macro Apply() Two bugs in the ReplaceAllFunc callback: 1. After yaml.Unmarshal failure, execution continued into Execute(), which could succeed and overwrite err with nil, silently swallowing the unmarshal error and producing output with default (empty) config. 2. After any error, the callback returned buffer.Bytes() (empty or partial) instead of the original match, corrupting the document. Return the original match bytes unchanged on either error so the directive is preserved in output and the error is not lost. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- macro/macro.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/macro/macro.go b/macro/macro.go index 256857f..eeea7d7 100644 --- a/macro/macro.go +++ b/macro/macro.go @@ -47,6 +47,7 @@ func (macro *Macro) Apply( err, "unable to unmarshal macros config template", ) + return match } var buffer bytes.Buffer @@ -60,6 +61,7 @@ func (macro *Macro) Apply( err, "unable to execute macros template", ) + return match } return buffer.Bytes()