Create Enum for exit codes

This commit is contained in:
runebaas 2018-05-06 02:00:45 +02:00
parent 2b85caeb29
commit fe5e2cb80f
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6
3 changed files with 27 additions and 8 deletions

View file

@ -0,0 +1,19 @@
namespace Geekbot.net.Lib
{
public enum GeekbotExitCode : int
{
// General
Clean = 0,
InvalidArguments = 1,
// Geekbot Internals
TranslationsFailed = 201,
// Dependent Services
RedisConnectionFailed = 301,
// Discord Related
CouldNotLogin = 401
}
}

View file

@ -72,7 +72,7 @@ namespace Geekbot.net.Lib.Localization
catch (Exception e) catch (Exception e)
{ {
_logger.Error(LogSource.Geekbot, "Failed to load Translations", e); _logger.Error(LogSource.Geekbot, "Failed to load Translations", e);
Environment.Exit(110); Environment.Exit(GeekbotExitCode.TranslationsFailed.GetHashCode());
} }
} }
@ -114,8 +114,8 @@ namespace Geekbot.net.Lib.Localization
} }
catch (Exception e) catch (Exception e)
{ {
_logger.Error(LogSource.Geekbot, "lol nope", e); _logger.Error(LogSource.Geekbot, "No translations for command found", e);
return new Dictionary<string, string>(); return new Dictionary<string, string>();
} }
} }
@ -127,7 +127,7 @@ namespace Geekbot.net.Lib.Localization
} }
catch (Exception e) catch (Exception e)
{ {
_logger.Error(LogSource.Geekbot, "lol nope", e); _logger.Error(LogSource.Geekbot, "No translations for command found", e);
return new Dictionary<string, string>(); return new Dictionary<string, string>();
} }
} }

View file

@ -43,7 +43,7 @@ namespace Geekbot.net
RunParameters runParameters = null; RunParameters runParameters = null;
Parser.Default.ParseArguments<RunParameters>(args) Parser.Default.ParseArguments<RunParameters>(args)
.WithParsed(e => runParameters = e) .WithParsed(e => runParameters = e)
.WithNotParsed(_ => Environment.Exit(1)); .WithNotParsed(_ => Environment.Exit(GeekbotExitCode.InvalidArguments.GetHashCode()));
var logo = new StringBuilder(); var logo = new StringBuilder();
logo.AppendLine(@" ____ _____ _____ _ ______ ___ _____"); logo.AppendLine(@" ____ _____ _____ _ ______ ___ _____");
@ -90,10 +90,10 @@ namespace Geekbot.net
catch (Exception e) catch (Exception e)
{ {
logger.Error(LogSource.Redis, "Redis Connection Failed", e); logger.Error(LogSource.Redis, "Redis Connection Failed", e);
Environment.Exit(102); Environment.Exit(GeekbotExitCode.RedisConnectionFailed.GetHashCode());
} }
_token = runParameters.Token ??_redis.StringGet("discordToken"); _token = runParameters.Token ?? _redis.StringGet("discordToken");
if (_token.IsNullOrEmpty) if (_token.IsNullOrEmpty)
{ {
Console.Write("Your bot Token: "); Console.Write("Your bot Token: ");
@ -187,7 +187,7 @@ namespace Geekbot.net
catch (Exception e) catch (Exception e)
{ {
_logger.Error(LogSource.Geekbot, "Could not connect...", e); _logger.Error(LogSource.Geekbot, "Could not connect...", e);
Environment.Exit(103); Environment.Exit(GeekbotExitCode.CouldNotLogin.GetHashCode());
} }
} }