Skip to content

Commit bdeb602

Browse files
committed
Add ReturnCode to DiagnosticToolException
1 parent 2814b51 commit bdeb602

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

src/Tools/Common/Commands/Utils.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,12 @@ public static void ResolveProcessForAttach(int processId, string name, string po
164164
{
165165
if (processId == -2)
166166
{
167-
throw new DiagnosticToolException($"Failed to launch dsrouter: {dsrouter}. Make sure that dotnet-dsrouter is not already running. You can connect to an already running dsrouter with -p.");
167+
throw new DiagnosticToolException($"Failed to launch dsrouter: {dsrouter}. Make sure that dotnet-dsrouter is not already running. You can connect to an already running dsrouter with -p.", (int)ReturnCode.TracingError);
168168
}
169169
else
170170
{
171171
throw new DiagnosticToolException($"Failed to launch dsrouter: {dsrouter}. Please make sure that dotnet-dsrouter is installed and available in the same directory as dotnet-trace.\n" +
172-
"You can install dotnet-dsrouter by running 'dotnet tool install --global dotnet-dsrouter'. More info at https://learn.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-dsrouter");
172+
"You can install dotnet-dsrouter by running 'dotnet tool install --global dotnet-dsrouter'. More info at https://learn.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-dsrouter", (int)ReturnCode.TracingError);
173173
}
174174
}
175175
}

src/Tools/Common/DiagnosticToolException.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ namespace Microsoft.Diagnostics.Tools
1818
// contextualized error messages, don't use this type.
1919
internal sealed class DiagnosticToolException : Exception
2020
{
21-
public DiagnosticToolException(string errorMessage) : base(errorMessage) { }
21+
public int ReturnCode { get; }
22+
public DiagnosticToolException(string errorMessage, int returnCode = 3 /* ReturnCode.ArgumentError */) : base(errorMessage)
23+
{
24+
ReturnCode = returnCode;
25+
}
2226
}
2327
}

src/Tools/dotnet-counters/CounterMonitor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ public async Task<ReturnCode> Monitor(
244244
catch (DiagnosticToolException dte)
245245
{
246246
_console.Error.WriteLine(dte.Message);
247-
return ReturnCode.ArgumentError;
247+
return (ReturnCode)dte.ReturnCode;
248248
}
249249
finally
250250
{
@@ -351,7 +351,7 @@ public async Task<ReturnCode> Collect(
351351
catch (DiagnosticToolException dte)
352352
{
353353
_console.Error.WriteLine(dte.Message);
354-
return ReturnCode.ArgumentError;
354+
return (ReturnCode)dte.ReturnCode;
355355
}
356356
finally
357357
{

src/Tools/dotnet-trace/CommandLine/Commands/CollectCommand.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -472,11 +472,7 @@ internal async Task<int> Collect(CancellationToken ct, CommandLineConfiguration
472472
{
473473
Console.Error.WriteLine($"[ERROR] {dte.Message}");
474474
collectionStopped = true;
475-
ret = (int)ReturnCode.ArgumentError;
476-
if (dte.Message.StartsWith("Failed to launch dsrouter", StringComparison.OrdinalIgnoreCase))
477-
{
478-
ret = (int)ReturnCode.TracingError;
479-
}
475+
ret = dte.ReturnCode;
480476
}
481477
catch (OperationCanceledException)
482478
{

src/Tools/dotnet-trace/CommandLine/Commands/CollectLinuxCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ internal int CollectLinux(CollectLinuxArgs args)
9090
catch (DiagnosticToolException dte)
9191
{
9292
Console.Error.WriteLine($"[ERROR] {dte.Message}");
93-
ret = (int)ReturnCode.ArgumentError;
93+
ret = dte.ReturnCode;
9494
}
9595
catch (Exception ex)
9696
{

0 commit comments

Comments
 (0)