Skip to content

Commit eac0f29

Browse files
authored
Print raw diff when there is error during jsonDiff for -json flag (#81)
1 parent 6c9fdfb commit eac0f29

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

writer/json.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"io"
7+
"os"
78

89
"github.com/dineshba/tf-summarize/terraformstate"
910
"github.com/dineshba/tf-summarize/tree"
@@ -40,7 +41,11 @@ func treeValue(t tree.Tree) interface{} {
4041
after, _ := json.Marshal(t.Value.Change.After)
4142
_, str := jsondiff.Compare(before, after, &opts)
4243
diff = make(map[string]interface{})
43-
_ = json.Unmarshal([]byte(str), &diff)
44+
err := json.Unmarshal([]byte(str), &diff)
45+
if err != nil {
46+
fmt.Fprintf(os.Stderr, "warning: unmarshalling diff error: %s\n", err)
47+
diff = fmt.Sprintf("raw diff: %s", str)
48+
}
4449
} else {
4550
if t.IsAddition() || t.IsImport() {
4651
diff = t.Value.Change.After

0 commit comments

Comments
 (0)