fix: check the value of encoder before encoding

This commit is contained in:
Srigovind Nayak 2024-11-16 22:49:18 +05:30
parent 7d74a20fe8
commit 3928222636
No known key found for this signature in database
GPG key ID: 09006810B7263D69

View file

@ -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)