Skip to content

Commit

Permalink
Add debugger display to Status (#2281)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK committed Sep 27, 2023
1 parent 46480fc commit 7e62218
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Grpc.Core.Api/Status.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
#endregion

using System;
using System.Diagnostics;

namespace Grpc.Core;

// TODO(jtattermusch): make the Status struct readonly
/// <summary>
/// Represents RPC result, which consists of <see cref="StatusCode"/> and an optional detail string.
/// </summary>
[DebuggerDisplay("{DebuggerToString(),nq}")]
public struct Status
{
/// <summary>
Expand Down Expand Up @@ -93,4 +95,19 @@ public override string ToString()
}
return $"Status(StatusCode=\"{StatusCode}\", Detail=\"{Detail}\")";
}

private string DebuggerToString()
{
var text = $"StatusCode = {StatusCode}";
if (!string.IsNullOrEmpty(Detail))
{
text += $@", Detail = ""{Detail}""";
}
if (DebugException != null)
{
text += $@", DebugException = ""{DebugException.GetType()}: {DebugException.Message}""";
}

return text;
}
}

0 comments on commit 7e62218

Please sign in to comment.