You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With more tests validating output of diagnostic tools, errors from
CommandUtils helpers should be validated as well. In facilitating error
checking, `src/Tools/Common/Commands/Utils.cs` has been refactored to
break unnecessary dependencies (e.g. using
`CommandUtils.FindProcessIdWithName` requires adding `IConsole.cs` to
project Compile items because `LineRewriter` depends on `IConsole`,
regardless of whether LineRewriter is used)
This PR does the following:
- Switch CounterMonitor back to using IConsole for output instead of
TextWriters (see commit message for more details
#5217 had switched from
IConsole to TextWriters)
- Rename CommandLineErrorException -> DiagnosticToolException to suggest
a more generic invalid usage of diagnostic tools, rather specifically a
command line exception.
- Update `CommandUtils` helpers to throw DiagnosticToolException to
allow callers to decide how to handle the message.
- Extend DiagnosticToolException (formerly CommandLineErrorException) to
specify ReturnCode
- Break ReturnCode + LineRewriter out of Utils.cs to have discrete
dependency chains for Project compile items.
- Rename Utils.cs -> CommandUtils.cs
- Keep `src/Tools/Common/Commands` command-only
Console.WriteLine("Invalid value for --dsrouter. Valid values are 'ios', 'ios-sim', 'android' and 'android-emu'.");
177
-
returnfalse;
160
+
thrownewDiagnosticToolException("Invalid value for --dsrouter. Valid values are 'ios', 'ios-sim', 'android' and 'android-emu'.");
178
161
}
179
162
if((processId=LaunchDSRouterProcess(dsrouter))<0)
180
163
{
181
164
if(processId==-2)
182
165
{
183
-
Console.WriteLine($"Failed to launch dsrouter: {dsrouter}. Make sure that dotnet-dsrouter is not already running. You can connect to an already running dsrouter with -p.");
166
+
thrownewDiagnosticToolException($"Failed to launch dsrouter: {dsrouter}. Make sure that dotnet-dsrouter is not already running. You can connect to an already running dsrouter with -p.",ReturnCode.TracingError);
184
167
}
185
168
else
186
169
{
187
-
Console.WriteLine($"Failed to launch dsrouter: {dsrouter}. Please make sure that dotnet-dsrouter is installed and available in the same directory as dotnet-trace.");
188
-
Console.WriteLine("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");
170
+
thrownewDiagnosticToolException($"Failed to launch dsrouter: {dsrouter}. Please make sure that dotnet-dsrouter is installed and available in the same directory as dotnet-trace.\n"+
171
+
"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",ReturnCode.TracingError);
189
172
}
190
-
returnfalse;
191
173
}
192
174
}
193
175
resolvedProcessId=processId;
194
-
returntrue;
195
176
}
196
177
}
197
-
198
-
internalsealedclassLineRewriter
199
-
{
200
-
publicintLineToClear{get;set;}
201
-
202
-
privateIConsoleConsole{get;}
203
-
204
-
publicLineRewriter(IConsoleconsole)
205
-
{
206
-
Console=console;
207
-
}
208
-
209
-
// ANSI escape codes:
210
-
// [2K => clear current line
211
-
// [{LineToClear};0H => move cursor to column 0 of row `LineToClear`
212
-
publicvoidRewriteConsoleLine()
213
-
{
214
-
booluseConsoleFallback=true;
215
-
if(!Console.IsInputRedirected)
216
-
{
217
-
// in case of console input redirection, the control ANSI codes would appear
0 commit comments