question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Logging failed mappings

See original GitHub issue

I’m developing an app that works with several other APIs, and the typical scenario is to record some interactions and use these records later as test data. Sometimes I need to edit a third-party response to a specific request, and I ofter run into trouble “no specific matching found”. I thought it would be ideal to save the data about failed matching to analyze it. How can I do it?

I use wiremock.net in tests like described here: https://github.com/WireMock-Net/WireMock.Net/wiki/Using-WireMock-in-UnitTests so my option is to use the last method from these tips (to access log entries via C# code): https://github.com/WireMock-Net/WireMock.Net/wiki/Request-Matching-Tips

I use it like this:

        private readonly WireMockServer _authServer = create(...);

        private static WireMockServer create(...)
        {
            var settings = new WireMockServerSettings
            {
                Urls = new[] { mockUri.AbsoluteUri },
                FileSystemHandler = new MyLocalFileSystemHandler(...),
                ReadStaticMappings = true,
            };
            return WireMockServer.Start(settings);
        }

        public void Stop()
        {
            logFailedRequests(_authServer);
            _authServer.Stop();
        }

        private static void logFailedRequests(WireMockServer server)
        {
            foreach (ILogEntry entry in server.LogEntries.Where(e => !e.PartialMatchResult.IsPerfectMatch))
            {
                string ser = JsonConvert.SerializeObject(entry, Formatting.Indented);
                File.WriteAllText(Path.Combine(..., entry.Guid + ".json"), ser);
            }
        }

The problem is that I have several mock servers, and even if I move logFailedRequests to some utility class, it’s a bit clunky to repeat this call in every mock before stopping and disposing. Right now, the only thing I can think of is, is to build a facade around WireMockNet and do the logging there.

What can I do to simplify this? Maybe some configuration trick or overriding of something.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
StefHcommented, Dec 24, 2021

OK. I’ll merge this PR and create a new official version in some time.

1reaction
LevYascommented, Dec 23, 2021

Thank you! Just checked, that worked, and the code was simplified significantly, well done! 👍

public class MyLocalFileSystemHandler : LocalFileSystemHandler
{
    private readonly string _mappingFolder;
    public MyLocalFileSystemHandler(string mappingFolder) => _mappingFolder = mappingFolder;

    public override string GetMappingFolder() => _mappingFolder;
    public override string GetUnmatchedRequestsFolder() => _mappingFolder;
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding invalid log errors
The following guide will help you understand and troubleshoot some of the common log related issues you might encounter. Field mapping types ...
Read more >
[Fleet] Change error logging of ignored mapping errors
In this case the error is ignored and a rollover is triggered by Fleet. It is misleading to log the mapping errors on...
Read more >
Mapping fails but does not show any logs in Informatica ...
In Informatica Data Quality (IDQ), when mapping fails, it does not display any logs in the Informatica Administrator monitoring tab.
Read more >
Error Failed mappings : Target - Trailhead - Salesforce
Got an error: "Failed mappings" and its "Target fields with invalid mappings" tells me the field name, this field is number with 2...
Read more >
Error during mapping check. failing recovery - how to solve ...
How to troubleshoot Elasticsearch/OpenSearch log "Error during mapping check. failing recovery" a detailed guide including background on ES concepts: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found