-
-
Notifications
You must be signed in to change notification settings - Fork 233
Add exception message to logging when mapping fails due to an exception. #1248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
eb7cf46
Add exception message to logging when mapping fails due to an exception.
JvE-iO eafc42b
Merge branch 'WireMock-Net:master' into patch-1
JvE-iO 4951ef3
Revert "Add exception message to logging when mapping fails due to an…
JvE-iO 2e247ff
Fix loggers with improved exception logging.
JvE-iO File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is also Error method with an exception. Would that also work for you?
https://github.com/WireMock-Net/WireMock.Net/blob/master/src/WireMock.Net.Abstractions/Logging/IWireMockLogger.cs#L57
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's already being used.
But
WireMock.Net.Xunit.TestOutputHelperWireMockLogger.Error(string formatString, Exception exception)expects the formatString to have a placeholder for the exception message.So it could also be fixed there. And in
WireMock.Logging.WireMockConsoleLogger.Error(string formatString, Exception exception).Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK I see, I did not detect this...
However, the reason that I did not expose the exception is because of security.The best way to detect if a mapping is working correct or incorrect is looking at the logging.
https://github.com/WireMock-Net/WireMock.Net/wiki/Request-Matching-Tips
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that eventually told me it was a perfect match.
But that was immediately followed by a "HttpStatusCode set to 404 : No matching mapping found".
And then you're in limbo.
WireMock says it has a matching mapping and WireMock says no matching mapping was found. Nothing else is logged.
I finally figured out what was going on by creating and injecting a custom IWireMockLogger that does log exception messages.
Not logging the exception message for security reasons sounds strange to me. How would anyone know that an exception has occurred then? Also, your loggers do log all the exception messages when the type is AggregateException.
Anyway, even changing it to something like
may help someone in the future a little bit.
Or maybe an exception occuring after a matching mapping has been found should not return a 404 with a "No matching mapping found" message. A 500 "something went wrong during the mapping" is probably more helpful.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I miss the context, but this line (from the consolelogger.cs) does log the exception?
_options.Logger.Error("HttpStatusCode set to 404 : No matching mapping found", ex);Example:
Logging is:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the TestOutputHelperWireMockLogger.cs could have an issue ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha, that clears up some of the confusion.
I'm not sure why, but when I asked Rider to show me the implementations of IWireMockLogger it "helpfully" included the decompiled version of a wiremock 1.5.1 nuget package I had on disk. There the WireMockConsoleLogger had the implementation without the placeholder for the exception message.
So we're left with just fixing these?
I've amended my PR.
Thank you for your patience in this :)