From c26ea00745c3cbef339d79fc8ae8818b8c61f64d Mon Sep 17 00:00:00 2001 From: Miguel Beltran Date: Thu, 17 Oct 2024 11:04:49 +0200 Subject: [PATCH] code simplification --- src/Raygun.Blazor/Models/ErrorDetails.cs | 41 +++++++++--------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/src/Raygun.Blazor/Models/ErrorDetails.cs b/src/Raygun.Blazor/Models/ErrorDetails.cs index e4a5f7e..1404860 100644 --- a/src/Raygun.Blazor/Models/ErrorDetails.cs +++ b/src/Raygun.Blazor/Models/ErrorDetails.cs @@ -130,45 +130,36 @@ internal ErrorDetails(Exception ex) { InnerError = new ErrorDetails(betterEx.InnerException); } - } - - if (StackTrace != null) - { - // If we have a stack trace then grab the debug info images, and put them into an array - // for the outgoing payload - Images = GetDebugInfoForStackFrames(StackTrace); + + Images = GetDebugInfoForStackFrames(new EnhancedStackTrace(ex).GetExternalFrames()); } } - + #endregion - + #region Private Properties - + private static readonly ConcurrentDictionary DebugInformationCache = new(); - private static Func AssemblyReaderProvider { get; set; } = PortableExecutableReaderExtensions.GetFileSystemPEReader; - + + private static Func AssemblyReaderProvider { get; set; } = + PortableExecutableReaderExtensions.GetFileSystemPEReader; + #endregion #region Privatate Methods - private static List GetDebugInfoForStackFrames(IEnumerable frames) + private static List GetDebugInfoForStackFrames(IEnumerable frames) { - if (DebugInformationCache.IsEmpty) - { - return []; - } - - var imageMap = DebugInformationCache.Values.Where(x => x?.Signature != null).ToDictionary(k => k!.Signature!); var imageSet = new HashSet(); - + foreach (var stackFrame in frames) { - if (stackFrame.ImageSignature != null && imageMap.TryGetValue(stackFrame.ImageSignature, out var image)) + var methodBase = stackFrame.GetMethod(); + if (methodBase == null) continue; + var debugInformation = TryGetDebugInformation(methodBase.Module.FullyQualifiedName); + if (debugInformation != null) { - if (image != null) - { - imageSet.Add(image); - } + imageSet.Add(debugInformation); } }