Skip to content

Commit

Permalink
code simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
miquelbeltran committed Oct 17, 2024
1 parent 5d3abdb commit c26ea00
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions src/Raygun.Blazor/Models/ErrorDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, PEDebugDetails?> DebugInformationCache = new();
private static Func<string, PEReader?> AssemblyReaderProvider { get; set; } = PortableExecutableReaderExtensions.GetFileSystemPEReader;


private static Func<string, PEReader?> AssemblyReaderProvider { get; set; } =
PortableExecutableReaderExtensions.GetFileSystemPEReader;

#endregion

#region Privatate Methods

private static List<PEDebugDetails> GetDebugInfoForStackFrames(IEnumerable<StackTraceDetails> frames)
private static List<PEDebugDetails> GetDebugInfoForStackFrames(IEnumerable<StackFrame> frames)
{
if (DebugInformationCache.IsEmpty)
{
return [];
}

var imageMap = DebugInformationCache.Values.Where(x => x?.Signature != null).ToDictionary(k => k!.Signature!);
var imageSet = new HashSet<PEDebugDetails>();

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);
}
}

Expand Down

0 comments on commit c26ea00

Please sign in to comment.