Skip to content

Commit

Permalink
Strip extra messages from aggregate exception
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjohnsonpint committed Apr 5, 2023
1 parent 9f5d295 commit 84761c7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/Sentry/Internal/Extensions/MiscExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,19 @@ public static void Add<TKey, TValue>(
TKey key,
TValue value) =>
collection.Add(new KeyValuePair<TKey, TValue>(key, value));

internal static string GetRawMessage(this AggregateException exception)
{
var message = exception.Message;
if (exception.InnerException is { } inner)
{
var i = message.IndexOf($" ({inner.Message})", StringComparison.Ordinal);
if (i > 0)
{
return message[..i];
}
}

return message;
}
}
3 changes: 2 additions & 1 deletion src/Sentry/Internal/MainExceptionProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Sentry.Extensibility;
using Sentry.Internal.Extensions;
using Sentry.Protocol;

namespace Sentry.Internal;
Expand Down Expand Up @@ -81,7 +82,7 @@ private SentryException BuildSentryException(Exception exception, Mechanism mech
{
Type = exception.GetType().FullName,
Module = exception.GetType().Assembly.FullName,
Value = exception.Message,
Value = exception is AggregateException agg ? agg.GetRawMessage() : exception.Message,
Mechanism = mechanism

// Note: ThreadID is not useful here because we don't send SentryThreads for exceptions.
Expand Down

0 comments on commit 84761c7

Please sign in to comment.