From 9cdf37c680623208c563dd7bc03a2d7b7a54416c Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Tue, 9 May 2023 15:10:44 -0700 Subject: [PATCH] Fix wrapped snapshot json output If there are a lot of snapshots, the JSON output can sometimes be wrapped to multiple console lines and need to be joined. --- restic.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/restic.go b/restic.go index ef3832e..54663eb 100644 --- a/restic.go +++ b/restic.go @@ -354,9 +354,11 @@ func (rcmd Restic) ReadSnapshots() ([]Snapshot, error) { return nil, fmt.Errorf("no snapshot output to parse: %w", ErrRestic) } + singleLineOutput := strings.Join(output.Stdout.Lines, "") + snapshots := new([]Snapshot) - if err = json.Unmarshal([]byte(output.Stdout.Lines[0]), snapshots); err != nil { - return nil, fmt.Errorf("failed parsing snapshot results from %s: %w", output.Stdout.Lines[0], err) + if err = json.Unmarshal([]byte(singleLineOutput), snapshots); err != nil { + return nil, fmt.Errorf("failed parsing snapshot results from %s: %w", singleLineOutput, err) } return *snapshots, nil