mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
Don't print stacktrace on exceptions specific to CliFx domain
This commit is contained in:
@@ -48,8 +48,10 @@ namespace CliFx
|
||||
// Fail if there are no commands defined
|
||||
if (!availableCommandSchemas.Any())
|
||||
{
|
||||
_console.WithColor(ConsoleColor.Red,
|
||||
c => c.Error.WriteLine("There are no commands defined in this application."));
|
||||
_console.WithColor(ConsoleColor.Red, c =>
|
||||
{
|
||||
c.Error.WriteLine("There are no commands defined in this application.");
|
||||
});
|
||||
|
||||
return -1;
|
||||
}
|
||||
@@ -64,8 +66,10 @@ namespace CliFx
|
||||
{
|
||||
isError = true;
|
||||
|
||||
_console.WithColor(ConsoleColor.Red,
|
||||
c => c.Error.WriteLine($"Specified command [{commandInput.CommandName}] is not defined."));
|
||||
_console.WithColor(ConsoleColor.Red, c =>
|
||||
{
|
||||
c.Error.WriteLine($"Specified command [{commandInput.CommandName}] is not defined.");
|
||||
});
|
||||
}
|
||||
|
||||
// Get parent command schema
|
||||
@@ -112,9 +116,15 @@ namespace CliFx
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_console.WithColor(ConsoleColor.Red, c => c.Error.WriteLine(ex));
|
||||
var message = ex is CliFxException ? ex.Message : ex.ToString();
|
||||
var exitCode = ex is CommandErrorException errorException ? errorException.ExitCode : -1;
|
||||
|
||||
return ex is CommandErrorException errorException ? errorException.ExitCode : -1;
|
||||
_console.WithColor(ConsoleColor.Red, c =>
|
||||
{
|
||||
c.Error.WriteLine(message);
|
||||
});
|
||||
|
||||
return exitCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace CliFx.Exceptions
|
||||
{
|
||||
public class CannotConvertCommandOptionException : Exception
|
||||
public class CannotConvertCommandOptionException : CliFxException
|
||||
{
|
||||
public CannotConvertCommandOptionException()
|
||||
{
|
||||
|
||||
21
CliFx/Exceptions/CliFxException.cs
Normal file
21
CliFx/Exceptions/CliFxException.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
|
||||
namespace CliFx.Exceptions
|
||||
{
|
||||
public abstract class CliFxException : Exception
|
||||
{
|
||||
protected CliFxException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
protected CliFxException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
protected CliFxException()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace CliFx.Exceptions
|
||||
{
|
||||
public class CommandErrorException : Exception
|
||||
public class CommandErrorException : CliFxException
|
||||
{
|
||||
public int ExitCode { get; }
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace CliFx.Exceptions
|
||||
{
|
||||
public class MissingCommandOptionException : Exception
|
||||
public class MissingCommandOptionException : CliFxException
|
||||
{
|
||||
public MissingCommandOptionException()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user