From 39282226368202533b4dc7ee06f4e28af764217e Mon Sep 17 00:00:00 2001 From: Srigovind Nayak <5201843+konidev20@users.noreply.github.com> Date: Sat, 16 Nov 2024 22:49:18 +0530 Subject: [PATCH] fix: check the value of encoder before encoding --- cmd/restic/cmd_tag.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/restic/cmd_tag.go b/cmd/restic/cmd_tag.go index ffd0ad7a8..4ea5fdaec 100644 --- a/cmd/restic/cmd_tag.go +++ b/cmd/restic/cmd_tag.go @@ -146,7 +146,13 @@ func runTag(ctx context.Context, opts TagOptions, gopts GlobalOptions, args []st } if gopts.JSON { - json.NewEncoder(gopts.stdout).Encode(changedSnapshots) + encoder := json.NewEncoder(gopts.stdout) + if encoder != nil { + err := encoder.Encode(changedSnapshots) + if err != nil { + return err + } + } } else { for _, changedSnapshot := range changedSnapshots { Printf("%v -> %v\n", changedSnapshot.Original, changedSnapshot.New)