Skip to content

Commit 1342c81

Browse files
stan-is-hateclaude
andauthored
feat(provider): expose verifier error sentinels for errors.Is discrimination (#577)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 889dc1e commit 1342c81

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

provider/errors.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package provider
2+
3+
import "github.com/pact-foundation/pact-go/v2/internal/native"
4+
5+
// Sentinel errors returned by Verifier.VerifyProvider so callers can
6+
// discriminate between a verification mismatch and an infrastructure failure
7+
// of the verifier itself. Pact-go publishes verification results to the broker
8+
// before returning ErrVerificationFailed (when PublishVerificationResults is
9+
// enabled), so callers that gate via can-i-merge / can-i-deploy can choose to
10+
// treat verification mismatches as non-fatal at the test step.
11+
var (
12+
// ErrVerificationFailed is returned when one or more consumer pact
13+
// verifications did not match the provider's responses. Verification
14+
// results are published to the broker before this error is returned.
15+
ErrVerificationFailed = native.ErrVerifierFailed
16+
17+
// ErrVerifierFailedToRun is returned when the verifier could not execute
18+
// at all — typically an infrastructure, configuration, or framework
19+
// problem. No verification results were published.
20+
ErrVerifierFailedToRun = native.ErrVerifierFailedToRun
21+
)

provider/errors_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package provider
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
"testing"
7+
8+
"github.com/pact-foundation/pact-go/v2/internal/native"
9+
)
10+
11+
// TestErrVerificationFailed_IsNativeSentinel guards the re-export: the
12+
// public provider.ErrVerificationFailed must remain identical to the
13+
// internal/native sentinel so callers can use errors.Is to discriminate
14+
// the error returned by Verifier.VerifyProvider.
15+
func TestErrVerificationFailed_IsNativeSentinel(t *testing.T) {
16+
if !errors.Is(ErrVerificationFailed, native.ErrVerifierFailed) {
17+
t.Errorf("ErrVerificationFailed must be the same sentinel as internal/native.ErrVerifierFailed")
18+
}
19+
if !errors.Is(ErrVerifierFailedToRun, native.ErrVerifierFailedToRun) {
20+
t.Errorf("ErrVerifierFailedToRun must be the same sentinel as internal/native.ErrVerifierFailedToRun")
21+
}
22+
}
23+
24+
// TestErrVerificationFailed_DiscriminatesFromGenericError makes sure the
25+
// sentinels are not confused with arbitrary error values.
26+
func TestErrVerificationFailed_DiscriminatesFromGenericError(t *testing.T) {
27+
generic := fmt.Errorf("something else broke")
28+
if errors.Is(generic, ErrVerificationFailed) {
29+
t.Error("generic error should not match ErrVerificationFailed")
30+
}
31+
if errors.Is(generic, ErrVerifierFailedToRun) {
32+
t.Error("generic error should not match ErrVerifierFailedToRun")
33+
}
34+
}
35+
36+
// TestErrVerificationFailed_DistinctFromEachOther ensures the two sentinels
37+
// are not interchangeable.
38+
func TestErrVerificationFailed_DistinctFromEachOther(t *testing.T) {
39+
if errors.Is(ErrVerificationFailed, ErrVerifierFailedToRun) {
40+
t.Error("ErrVerificationFailed and ErrVerifierFailedToRun must be distinct")
41+
}
42+
}

0 commit comments

Comments
 (0)