-
-
Notifications
You must be signed in to change notification settings - Fork 508
Expand file tree
/
Copy pathErrorExtensions.cs
More file actions
84 lines (70 loc) · 2.49 KB
/
ErrorExtensions.cs
File metadata and controls
84 lines (70 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using Exceptionless.Core.Models;
using Exceptionless.Core.Models.Data;
using Foundatio.Serializer;
namespace Exceptionless.Core.Extensions;
public static class ErrorExtensions
{
public static void SetTargetInfo(this Error error, SettingsDictionary targetInfo)
{
error.Data ??= new DataDictionary();
error.Data[Error.KnownDataKeys.TargetInfo] = targetInfo;
}
public static void SetTargetInfo(this SimpleError error, SettingsDictionary targetInfo)
{
error.Data ??= new DataDictionary();
error.Data[Error.KnownDataKeys.TargetInfo] = targetInfo;
}
public static StackingTarget GetStackingTarget(this Error error)
{
ArgumentNullException.ThrowIfNull(error);
InnerError? targetError = error;
while (targetError is not null)
{
var frame = targetError.StackTrace?.FirstOrDefault(st => st.IsSignatureTarget.GetValueOrDefault());
if (frame is not null)
return new StackingTarget
{
Error = targetError,
Method = frame
};
if (targetError.TargetMethod is not null && targetError.TargetMethod.IsSignatureTarget.GetValueOrDefault())
return new StackingTarget
{
Error = targetError,
Method = targetError.TargetMethod
};
targetError = targetError.Inner;
}
// fallback to default
var defaultError = error.GetInnermostError();
var defaultMethod = defaultError.StackTrace?.FirstOrDefault();
if (defaultMethod is null && error.StackTrace is { Count: > 0 })
{
defaultMethod = error.StackTrace?.FirstOrDefault();
defaultError = error;
}
return new StackingTarget
{
Error = defaultError,
Method = defaultMethod
};
}
public static StackingTarget? GetStackingTarget(this Event ev, ITextSerializer serializer)
{
var error = ev.GetError(serializer);
return error?.GetStackingTarget();
}
public static InnerError GetInnermostError(this InnerError error)
{
ArgumentNullException.ThrowIfNull(error);
var current = error;
while (current.Inner is not null)
current = current.Inner;
return current;
}
}
public record StackingTarget
{
public required Method? Method { get; init; }
public required InnerError Error { get; init; }
}