Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create clear error messages for dotnet-trace #3012

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions src/Tools/dotnet-trace/CommandLine/Commands/CollectCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private static async Task<int> Collect(CancellationToken ct, IConsole console, i

using (DiagnosticsClientHolder holder = await builder.Build(ct, processId, diagnosticPort, showChildIO: showchildio, printLaunchCommand: true))
{
string processMainModuleFileName = "";
string processMainModuleFileName = $"Process{processId}";

// if builder returned null, it means we received ctrl+C while waiting for clients to connect. Exit gracefully.
if (holder == null)
Expand All @@ -193,23 +193,20 @@ private static async Task<int> Collect(CancellationToken ct, IConsole console, i
{
// Reading the process MainModule filename can fail if the target process closes
// or isn't fully setup. Retry a few times to attempt to address the issue
for (int attempts = 0; true; attempts++)
for (int attempts = 0; attempts < 10; attempts++)
{
try
{
processMainModuleFileName = process.MainModule.FileName;
break;
}

catch
{
if (attempts > 10)
{
Console.Error.WriteLine("Unable to examine process.");
return ReturnCode.SessionCreationError;
}
Thread.Sleep(200);
}
}

}

if (String.Equals(output.Name, DefaultTraceName, StringComparison.OrdinalIgnoreCase))
Expand Down Expand Up @@ -242,9 +239,18 @@ private static async Task<int> Collect(CancellationToken ct, IConsole console, i
}
}
}
catch (DiagnosticsClientException e)
catch (Exception ex) when (ex is DiagnosticsClientException || ex is System.UnauthorizedAccessException)
mikelle-rogers marked this conversation as resolved.
Show resolved Hide resolved
{
Console.Error.WriteLine($"Unable to start a tracing session: {e.ToString()}");
if (ex is DiagnosticsClientException)
{
Console.Error.WriteLine($"Unable to start a tracing session: {ex.ToString()}");
}
else
{
Console.Error.WriteLine($"dotnet-trace does not have permission to access the specified app: {ex.GetType()}");
mikelle-rogers marked this conversation as resolved.
Show resolved Hide resolved
return ReturnCode.SessionCreationError;
}

}

if (session == null)
Expand Down