-
-
Notifications
You must be signed in to change notification settings - Fork 207
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
Expose EnumerateChainedExceptions #1733
Changes from all commits
e144927
5e7c87c
67fb4bb
87080f2
878e19b
c77e432
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using Sentry; | ||
using Sentry.Internal; | ||
|
||
/// <summary> | ||
|
@@ -18,6 +20,42 @@ public static class SentryExceptionExtensions | |
public static void AddSentryTag(this Exception ex, string name, string value) | ||
=> ex.Data.Add($"{MainExceptionProcessor.ExceptionDataTagKey}{name}", value); | ||
|
||
/// <summary> | ||
/// Recursively enumerates all <see cref="AggregateException.InnerExceptions"/> and <see cref="Exception.InnerException"/> | ||
/// Not for public use. | ||
/// </summary> | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public static IEnumerable<Exception> EnumerateChainedExceptions(this Exception exception, SentryOptions options) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This not being for public use but part of the Or perhaps this is best not being an extension method of Exception? If it's under a different namespace it will already help not show up on the user's intellisense. The goal is to share the built-in behavior with the Unity IL2CPP support There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm ok with it as is, since it includes a
SimonCropp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
if (exception is AggregateException aggregateException) | ||
{ | ||
foreach (var inner in EnumerateInner(options, aggregateException)) | ||
{ | ||
yield return inner; | ||
} | ||
|
||
if (!options.KeepAggregateException) | ||
{ | ||
yield break; | ||
} | ||
} | ||
else if (exception.InnerException != null) | ||
{ | ||
foreach (var inner in exception.InnerException.EnumerateChainedExceptions(options)) | ||
{ | ||
yield return inner; | ||
} | ||
} | ||
|
||
yield return exception; | ||
} | ||
|
||
private static IEnumerable<Exception> EnumerateInner(SentryOptions options, AggregateException aggregateException) | ||
{ | ||
return aggregateException.InnerExceptions | ||
.SelectMany(exception => exception.EnumerateChainedExceptions(options)); | ||
} | ||
|
||
/// <summary> | ||
/// Set a Sentry's structured Context to the Exception. | ||
/// </summary> | ||
|
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 was thinking we could refactor out this class to have a base class, so that the code that follows it doesn't need to iterate on the exceptions once again:
https://github.com/getsentry/sentry-unity/pull/683/files#diff-d7c6f55c576cbd905ba5affcc1c578fd120655cdfcdc520994c837efeeebccc2R33
Then a third time to have the original + the Sentry exception side by side:
https://github.com/getsentry/sentry-unity/pull/683/files#diff-d7c6f55c576cbd905ba5affcc1c578fd120655cdfcdc520994c837efeeebccc2R47
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.
@bruno-garcia i dont really understand what you are proposing here. can we sync my tuesday morning?
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 thought of re-thinking these hooks but didn't get that far, #1734