mirror of
https://github.com/kovetskiy/mark.git
synced 2026-03-17 07:57:37 +08:00
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>
This commit is contained in:
parent
3e71d65f61
commit
4c81c81fb3
@ -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()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user