Skip to content

Commit 7e62218

Browse files
authored
Add debugger display to Status (#2281)
1 parent 46480fc commit 7e62218

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/Grpc.Core.Api/Status.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
#endregion
1616

1717
using System;
18+
using System.Diagnostics;
1819

1920
namespace Grpc.Core;
2021

2122
// TODO(jtattermusch): make the Status struct readonly
2223
/// <summary>
2324
/// Represents RPC result, which consists of <see cref="StatusCode"/> and an optional detail string.
2425
/// </summary>
26+
[DebuggerDisplay("{DebuggerToString(),nq}")]
2527
public struct Status
2628
{
2729
/// <summary>
@@ -93,4 +95,19 @@ public override string ToString()
9395
}
9496
return $"Status(StatusCode=\"{StatusCode}\", Detail=\"{Detail}\")";
9597
}
98+
99+
private string DebuggerToString()
100+
{
101+
var text = $"StatusCode = {StatusCode}";
102+
if (!string.IsNullOrEmpty(Detail))
103+
{
104+
text += $@", Detail = ""{Detail}""";
105+
}
106+
if (DebugException != null)
107+
{
108+
text += $@", DebugException = ""{DebugException.GetType()}: {DebugException.Message}""";
109+
}
110+
111+
return text;
112+
}
96113
}

0 commit comments

Comments
 (0)