Skip to content

Fix to_nice_yaml scalar corruption in borgmatic hooks#199

Open
ramcq wants to merge 2 commits intoborgbase:masterfrom
ramcq:patch-1
Open

Fix to_nice_yaml scalar corruption in borgmatic hooks#199
ramcq wants to merge 2 commits intoborgbase:masterfrom
ramcq:patch-1

Conversation

@ramcq
Copy link
Copy Markdown

@ramcq ramcq commented Mar 11, 2026

Resurrects #118, rebased onto current master. to_nice_yaml applied to a scalar value (like a healthchecks URL) produces "value\n...\n" - the YAML document end marker corrupts the config. The per-hook loop applies to_nice_yaml to each hook value individually, triggering this bug for any scalar hook such as a healthcheck URL.

This fix applies to_nice_yaml to the entire borgmatic_hooks dict in a single invocation, avoiding the scalar case entirely, and extends the width to 1000 to prevent PyYAML wrapping long strings (like URLs) at 80 chars. Fix applied to both config.yaml.j2 (borgmatic >= 1.8) and config_1.7.yaml.j2 (borgmatic < 1.8).

Note: yamllint does not catch this bug: the indented ... is parsed as part of the scalar string, making it syntactically valid but semantically wrong for borgbackup. A molecule verify assertion is included that checks the rendered config does not contain the ... string at the content level.

Fixes #117

ramcq and others added 2 commits March 11, 2026 23:39
)

Add a healthchecks scalar URL to the molecule converge playbook and
a verify assertion that checks the rendered borgmatic config doesn't
contain '...' (YAML document end marker) in the healthchecks value.
This catches the bug where to_nice_yaml on a scalar produces
"value\n...\n" which corrupts the config.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…#117)

Invoking to_nice_yaml on a scalar value generates a two-line YAML
document "value\n...\n" which corrupts the value of a hook such as
healthchecks which is just a single string URL. Instead of looping
over each of the hooks, apply to_nice_yaml to the entire hooks dict
in a single invocation. Add width=1000 to prevent PyYAML from
wrapping long strings (like URLs) at 80 chars.

Fix both config.yaml.j2 (borgmatic >= 1.8) and config_1.7.yaml.j2
(borgmatic < 1.8).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unusual YAML syntax for hooks

1 participant