dotnet / diagnostics

This repository contains the source code for various .NET Core runtime diagnostic tools and documents.
MIT License
1.18k stars 354 forks source link

Translate HRESULT error codes from the DiagnosticClient into human-readable exceptions #2784

Open kelltrick opened 2 years ago

kelltrick commented 2 years ago

We should translate the HRESULT exception codes we receive from DiagnosticClient into meaningful human-readable descriptions of the codes.

Background and Motivation

When we get an error from the DiagnosticClient it will look something like this:

=> TargetProcessId:11588 TargetRuntimeInstanceCookie:8fc502a39434444ab2c67aaed1b27a5b CollectionRuleName:LoadAllocationProfiler => CollectionRuleTriggerType:Startup => CollectionRuleActionType:LoadProfiler CollectionRuleActionIndex:0
      Collection rule 'LoadAllocationProfiler' action 'LoadProfiler' failed.
      Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Exceptions.CollectionRuleActionException: SetStartupProfilerAsync failed - HRESULT: 0x8013135B

Proposed Feature

We should translate the code 0x8013135B into it's description "Not Yet Available". Full list of codes here: dotnet/runtime:/src/native/eventpipe/ds-types.h: line 127

The example above would look something like this:

=> TargetProcessId:11588 TargetRuntimeInstanceCookie:8fc502a39434444ab2c67aaed1b27a5b CollectionRuleName:LoadAllocationProfiler => CollectionRuleTriggerType:Startup => CollectionRuleActionType:LoadProfiler CollectionRuleActionIndex:0
      Collection rule 'LoadAllocationProfiler' action 'LoadProfiler' failed.
      Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Exceptions.CollectionRuleActionException: SetStartupProfilerAsync failed - IPC Command Not Yet Available (HRESULT: 0x8013135B)
jander-msft commented 2 years ago

I think exposing the command HRESULT on ServerErrorException (https://github.com/dotnet/diagnostics/blob/main/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/DiagnosticsClientExceptions.cs#L27) by either setting Exception.HResult or adding a new property would be a great start such that the caller could make some informed decision on what to do next instead of just giving up. This would also allow the caller to provide custom messaging for specific problems and possible resolutions.