Did the ThrowExceptionWhenMatcherFails option got removed from 1.5.16 to 1.5.51? #587

Closed
opened 2025-12-29 08:30:38 +01:00 by adam · 4 comments
Owner

Originally created by @JasonLandbridge on GitHub (Mar 29, 2024).

Originally assigned to: @StefH on GitHub.

Hi there,

I just upgraded to .NET 8 and upgraded Wiremock from 1.5.16 to 1.5.51, but the ThrowExceptionWhenMatcherFails option seems to not be there anymore?

        Server = WireMockServer.Start(new WireMockServerSettings()
        {
            // Cannot resolve symbol 'ThrowExceptionWhenMatcherFails'
            ThrowExceptionWhenMatcherFails = true,
            HostingScheme = HostingScheme.HttpAndHttps,
        });

Searching the repo for any mention of ThrowExceptionWhenMatcherFails seems it has disappeared.

Did I miss a breaking change or migration?

Thanks!

Originally created by @JasonLandbridge on GitHub (Mar 29, 2024). Originally assigned to: @StefH on GitHub. Hi there, I just upgraded to .NET 8 and upgraded Wiremock from 1.5.16 to 1.5.51, but the `ThrowExceptionWhenMatcherFails` option seems to not be there anymore? ```csharp Server = WireMockServer.Start(new WireMockServerSettings() { // Cannot resolve symbol 'ThrowExceptionWhenMatcherFails' ThrowExceptionWhenMatcherFails = true, HostingScheme = HostingScheme.HttpAndHttps, }); ``` Searching the repo for any mention of `ThrowExceptionWhenMatcherFails` seems it has disappeared. Did I miss a breaking change or migration? Thanks!
adam added the question label 2025-12-29 08:30:38 +01:00
adam closed this issue 2025-12-29 08:30:38 +01:00
Author
Owner

@StefH commented on GitHub (Mar 30, 2024):

@JasonLandbridge
Sorry, this was indeed a small breaking change introduced in https://github.com/WireMock-Net/WireMock.Net/pull/986 in version 1.5.36 (21 September 2023).

This property was removed, and now you get logging in case the matcher fails.

@StefH commented on GitHub (Mar 30, 2024): @JasonLandbridge Sorry, this was indeed a small breaking change introduced in https://github.com/WireMock-Net/WireMock.Net/pull/986 in version 1.5.36 (21 September 2023). This property was removed, and now you get logging in case the matcher fails.
Author
Owner

@JasonLandbridge commented on GitHub (Mar 30, 2024):

@StefH Thanks for tracking this down! I actually loved this option as it would make my tests fail if an URL changed or a new URL was called by my code not yet covered by my tests. But now, I assume, the tests can still pass due to the lack of a thrown exception if this happens.

Any chance this option can be returned or is there something similar available?

Cheers!

@JasonLandbridge commented on GitHub (Mar 30, 2024): @StefH Thanks for tracking this down! I actually loved this option as it would make my tests fail if an URL changed or a new URL was called by my code not yet covered by my tests. But now, I assume, the tests can still pass due to the lack of a thrown exception if this happens. Any chance this option can be returned or is there something similar available? Cheers!
Author
Owner

@StefH commented on GitHub (Mar 30, 2024):

The functionality is like:

constructor

When creating a matcher using the constructor, and the pattern is invalid, an exception is thrown immediately.
Like:

    [Fact]
    public void JsonMatcher_WithInvalidStringValue_Should_ThrowException()
    {
        // Act
        // ReSharper disable once ObjectCreationAsStatement
        Action action = () => new JsonMatcher(MatchBehaviour.AcceptOnMatch, "{ \"Id\"");

        // Assert
        action.Should().Throw<JsonException>();
    }

    // or this
    [Fact]
    public void GraphQLMatcher_For_InvalidSchema_ThrowsGraphQLSyntaxErrorException()
    {
        // Act
        // ReSharper disable once ObjectCreationAsStatement
        Action action = () => _ = new GraphQLMatcher("in va lid");

        // Assert
        action.Should().Throw<GraphQLSyntaxErrorException>();
    }

during matching

When the input value for the matcher to match on, is invalid, the exception is remembered and returned in the result.
Like:

    [Fact]
    public void GraphQLMatcher_For_ValidSchema_And_IncorrectQueryWithError_WithThrowExceptionTrue_ReturnsError()
    {
        // Arrange
        var input = "{\"query\":\"{\\r\\n studentsX {\\r\\n fullName\\r\\n X\\r\\n }\\r\\n}\"}";

        // Act
        var matcher = new GraphQLMatcher(TestSchema);
        var result = matcher.IsMatch(input);

        // Assert
        result.Score.Should().Be(MatchScores.Mismatch);
        result.Exception!.Message.Should().StartWith("Cannot query field 'studentsX' on type 'Query'");
    }

In the high level mapping matcher code, this error/exception is logged and this mapping is skipped because it contains errors.

Does this help you, you did you actually use it in a different way ?
Because I do not understand this:

it would make my tests fail if an URL changed or a new URL was called by my code not yet covered by my tests

@StefH commented on GitHub (Mar 30, 2024): The functionality is like: ### constructor When creating a matcher using the constructor, and the pattern is invalid, an exception is thrown immediately. Like: ``` c# [Fact] public void JsonMatcher_WithInvalidStringValue_Should_ThrowException() { // Act // ReSharper disable once ObjectCreationAsStatement Action action = () => new JsonMatcher(MatchBehaviour.AcceptOnMatch, "{ \"Id\""); // Assert action.Should().Throw<JsonException>(); } // or this [Fact] public void GraphQLMatcher_For_InvalidSchema_ThrowsGraphQLSyntaxErrorException() { // Act // ReSharper disable once ObjectCreationAsStatement Action action = () => _ = new GraphQLMatcher("in va lid"); // Assert action.Should().Throw<GraphQLSyntaxErrorException>(); } ``` ### during matching When the input value for the matcher to match on, is invalid, the exception is remembered and returned in the result. Like: ``` c# [Fact] public void GraphQLMatcher_For_ValidSchema_And_IncorrectQueryWithError_WithThrowExceptionTrue_ReturnsError() { // Arrange var input = "{\"query\":\"{\\r\\n studentsX {\\r\\n fullName\\r\\n X\\r\\n }\\r\\n}\"}"; // Act var matcher = new GraphQLMatcher(TestSchema); var result = matcher.IsMatch(input); // Assert result.Score.Should().Be(MatchScores.Mismatch); result.Exception!.Message.Should().StartWith("Cannot query field 'studentsX' on type 'Query'"); } ``` In the high level mapping matcher code, this error/exception is logged and this mapping is skipped because it contains errors. Does this help you, you did you actually use it in a different way ? Because I do not understand this: > it would make my tests fail if an URL changed or a new URL was called by my code not yet covered by my tests
Author
Owner

@JasonLandbridge commented on GitHub (Apr 3, 2024):

Thank you very much for this answer! I will try it out when I have the chance. I will close this for now

@JasonLandbridge commented on GitHub (Apr 3, 2024): Thank you very much for this answer! I will try it out when I have the chance. I will close this for now
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#587