Skip to content

Commit

Permalink
Print raw diff when there is error during jsonDiff for -json flag (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
dineshba authored Oct 24, 2024
1 parent 6c9fdfb commit eac0f29
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion writer/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"io"
"os"

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

0 comments on commit eac0f29

Please sign in to comment.