Skip to content

Commit

Permalink
Merge pull request #73851 from davidwengier/ReportMarker
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwengier authored Jun 12, 2024
2 parents 4ae59f1 + 1921ec6 commit f8ad77d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Compilers/Core/Portable/InternalUtilities/FatalError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,10 @@ public static bool ReportAndCatchUnlessCanceled(Exception exception, Cancellatio

#endif

private static readonly object s_reportedMarker = new();
// We use a Guid for the marker because it is used as a key in an exceptions Data dictionary, so we must make sure
// it's serializable if the exception crosses an RPC boundary. In particular System.Text.Json doesn't like plain
// object dictionary keys.
private static readonly object s_reportedMarker = Guid.NewGuid();

// Do not allow this method to be inlined. That way when we have a dump we can see this frame in the stack and
// can examine things like s_reportedExceptionMessage. Without this, it's a lot tricker as FatalError is linked
Expand Down
14 changes: 14 additions & 0 deletions src/Workspaces/CoreTest/UtilityTest/ExceptionHelpersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#nullable disable

using System;
using System.Text.Json;
using Microsoft.CodeAnalysis.ErrorReporting;
using Roslyn.Test.Utilities;
using Roslyn.Utilities;
Expand Down Expand Up @@ -55,5 +56,18 @@ void a()

Assert.True(false, "Should have returned in the catch block before this point.");
}

[Fact]
public void ErrorReporting_SerializesException()
{
FatalError.SetHandlers(delegate { }, delegate { });

var e = new Exception("Hello");
FatalError.ReportNonFatalError(e);

Assert.NotEmpty(e.Data);
Assert.NotNull(JsonSerializer.Serialize(e));
Assert.NotNull(Newtonsoft.Json.JsonConvert.SerializeObject(e));
}
}
}

0 comments on commit f8ad77d

Please sign in to comment.