Skip to content

Commit 0199f01

Browse files
committed
feat(verifier): Throw more specific exception when verification fails
Resolves pact-foundation#505
1 parent 27df006 commit 0199f01

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
3+
namespace PactNet.Exceptions
4+
{
5+
/// <summary>
6+
/// Pact verification failed
7+
/// </summary>
8+
[Serializable]
9+
public class PactVerificationFailedException : PactFailureException
10+
{
11+
/// <summary>
12+
/// Initializes a new instance of the <see cref="PactVerificationFailedException" /> class
13+
/// </summary>
14+
public PactVerificationFailedException()
15+
: this("The pact failed verification")
16+
{
17+
}
18+
19+
/// <summary>
20+
/// Initializes a new instance of the <see cref="PactVerificationFailedException" /> class
21+
/// </summary>
22+
/// <param name="message">The message that describes the error</param>
23+
public PactVerificationFailedException(string message) : base(message)
24+
{
25+
}
26+
27+
/// <summary>
28+
/// Initializes a new instance of the <see cref="PactVerificationFailedException" /> class
29+
/// </summary>
30+
/// <param name="message">The error message that explains the reason for the exception</param>
31+
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified</param>
32+
public PactVerificationFailedException(string message, Exception innerException) : base(message, innerException)
33+
{
34+
}
35+
}
36+
}

Diff for: src/PactNet/Verifier/InteropVerifierProvider.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public void Execute()
235235

236236
string error = result switch
237237
{
238-
1 => "Pact verification failed",
238+
1 => throw new PactVerificationFailedException("Pact verification failed"),
239239
2 => "Failed to run the verification",
240240
_ => $"An unknown error occurred: {result}"
241241
};

Diff for: tests/PactNet.Tests/Verifier/InteropVerifierProviderTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void HappyPathIntegrationTest()
5353

5454
Action action = () => provider.Execute();
5555

56-
action.Should().Throw<PactFailureException>();
56+
action.Should().Throw<PactVerificationFailedException>();
5757
}
5858

5959
[Fact]
@@ -73,7 +73,7 @@ public void SetPublishOptions_NoBuildUri_IsValid()
7373

7474
Action action = () => provider.Execute();
7575

76-
action.Should().Throw<PactFailureException>();
76+
action.Should().Throw<PactVerificationFailedException>();
7777
}
7878
}
7979
}

0 commit comments

Comments
 (0)