borgmatic create --json errors when Borg includes non-JSON warnings in JSON output #847
Labels
No Label
blocked
bug
data loss
design finalized
good first issue
new feature area
question / support
security
waiting for response
No Milestone
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: borgmatic-collective/borgmatic#847
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What I'm trying to do and why
I'm trying to run
borgmatic create --json
so that I can consume its output programmatically as part of prototyping another ticket. This generally works—except when I pass Borg a non-existent source directory, in which case Borg includes a non-JSON warning in its output which borgmatic then chokes on as it expects JSON. (borgmatic parses the JSON instead of just passing it through to stdout/logging because borgmatic provides the service of combining JSON output from multiple Borg runs.)Steps to reproduce
source_directories
.borgmatic create -c yourconfig.yaml --verbosity 2 --json
Actual behavior
Relevant borgmatic output:
Under the hood, Borg outputs something like the following for borgmatic to choke on:
Expected behavior
Ideally Borg wouldn't output non-JSON output with
--json
on, but lacking that, maybe borgmatic could ignore the non-JSON portion.Other notes / implementation ideas
One way to ignore the non-JSON portion would be scan for the first
{
and discard anything prior. May not be foolproof though.borgmatic version
main
borgmatic installation method
pipx install --editable
Borg version
1.2.7
Python version
3.11.8
Database version (if applicable)
No response
Operating system and version
Manjaro stable
I went with the solution of scanning for the first
{
to start parsing JSON, but only if it's at the start of a line. Should be a little more robust that way.Released in 1.8.10!