make InvalidOperationException thrown by RunCommand graceful (#5525)
This commit is contained in:
parent
2d93968a88
commit
3fce02e583
2 changed files with 11 additions and 2 deletions
|
@ -7,6 +7,13 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
{
|
||||
internal static class ExceptionExtensions
|
||||
{
|
||||
public static TException DisplayAsError<TException>(this TException exception)
|
||||
where TException : Exception
|
||||
{
|
||||
exception.Data.Add(CLI_User_Displayed_Exception, true);
|
||||
return exception;
|
||||
}
|
||||
|
||||
public static void ReportAsWarning(this Exception e)
|
||||
{
|
||||
Reporter.Verbose.WriteLine($"Warning: Ignoring exception: {e.ToString().Yellow()}");
|
||||
|
|
|
@ -121,12 +121,14 @@ namespace Microsoft.DotNet.Tools.Run
|
|||
{
|
||||
throw new InvalidOperationException(
|
||||
$"{LocalizableStrings.RunCommandInvalidOperationException1} {directory}." + Environment.NewLine +
|
||||
LocalizableStrings.RunCommandInvalidOperationException2);
|
||||
LocalizableStrings.RunCommandInvalidOperationException2)
|
||||
.DisplayAsError();
|
||||
}
|
||||
else if (projectFiles.Length > 1)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"{LocalizableStrings.RunCommandInvalidOperationException3}'{directory}'{LocalizableStrings.RunCommandInvalidOperationException4}");
|
||||
$"{LocalizableStrings.RunCommandInvalidOperationException3}'{directory}'{LocalizableStrings.RunCommandInvalidOperationException4}")
|
||||
.DisplayAsError();
|
||||
}
|
||||
|
||||
Project = projectFiles[0];
|
||||
|
|
Loading…
Reference in a new issue