Skip to content

Commit 394f7c8

Browse files
fix: slsa-framework#642: don't use go-cmp for outputting diff (slsa-framework#737)
Previously we used the go-cmp's Diff for displaying a human-friendly diff between two structs in an error message. I had intended to do a json print of the structs and do a line-by-line diff. There is an internal library for calculating text diff, but I don't see any external functions that expose it to make it available for our use: https://pkg.go.dev/golang.org/x/tools/internal/diff Instead, this we will simply display both structs in their own "actual" and "expected" sections. The user can use their other tools to find a human-friendly diff. Signed-off-by: Ramon Petgrave <[email protected]>
1 parent 3d268db commit 394f7c8

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

verifiers/internal/gcb/provenance.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010

1111
"golang.org/x/exp/slices"
1212

13-
"github.com/google/go-cmp/cmp"
1413
intoto "github.com/in-toto/in-toto-golang/in_toto"
1514
dsselib "github.com/secure-systems-lab/go-securesystemslib/dsse"
1615

@@ -173,8 +172,8 @@ func (p *Provenance) VerifyTextProvenance() error {
173172
// they are both taken from a string representation.
174173
// We do not use cmp.Equal() because it *can* panic and is intended for unit tests only.
175174
if !reflect.DeepEqual(unverifiedTextIntotoStatement, p.verifiedStatement) {
176-
return fmt.Errorf("%w: diff '%s'", serrors.ErrorMismatchIntoto,
177-
cmp.Diff(unverifiedTextIntotoStatement, p.verifiedStatement))
175+
return fmt.Errorf("%w: \nunverified: %v, \nverified: %v", serrors.ErrorMismatchIntoto,
176+
unverifiedTextIntotoStatement, p.verifiedStatement)
178177
}
179178

180179
return nil

0 commit comments

Comments
 (0)