Commit 3397dcdc authored by Nick Craver's avatar Nick Craver

Cleanup: ExceptionFactory

parent f7a4110e
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
namespace StackExchange.Redis
{
internal static class ExceptionFactory
{
const string DataCommandKey = "redis-command",
DataServerKey = "redis-server",
DataServerEndpoint = "server-endpoint",
DataConnectionState = "connection-state",
DataLastFailure = "last-failure",
DataLastInnerException = "last-innerexception",
DataSentStatusKey = "request-sent-status";
private const string
DataCommandKey = "redis-command",
DataSentStatusKey = "request-sent-status",
DataServerKey = "redis-server";
internal static Exception AdminModeNotEnabled(bool includeDetail, RedisCommand command, Message message, ServerEndPoint server)
{
......@@ -24,6 +18,7 @@ internal static Exception AdminModeNotEnabled(bool includeDetail, RedisCommand c
if (includeDetail) AddDetail(ex, message, server, s);
return ex;
}
internal static Exception CommandDisabled(bool includeDetail, RedisCommand command, Message message, ServerEndPoint server)
{
string s = GetLabel(includeDetail, command, message);
......@@ -31,6 +26,7 @@ internal static Exception CommandDisabled(bool includeDetail, RedisCommand comma
if (includeDetail) AddDetail(ex, message, server, s);
return ex;
}
internal static Exception TooManyArgs(bool includeDetail, string command, Message message, ServerEndPoint server, int required)
{
string s = GetLabel(includeDetail, command, message);
......@@ -38,6 +34,7 @@ internal static Exception TooManyArgs(bool includeDetail, string command, Messag
if (includeDetail) AddDetail(ex, message, server, s);
return ex;
}
internal static Exception CommandDisabled(bool includeDetail, string command, Message message, ServerEndPoint server)
{
string s = GetLabel(includeDetail, command, message);
......@@ -106,7 +103,7 @@ internal static string GetInnerMostExceptionMessage(Exception e)
return e.Message;
}
}
internal static Exception NoConnectionAvailable(bool includeDetail, bool includePerformanceCounters, RedisCommand command, Message message, ServerEndPoint server, ServerEndPoint[] serverSnapshot)
{
string commandLabel = GetLabel(includeDetail, command, message);
......@@ -135,7 +132,7 @@ internal static Exception NoConnectionAvailable(bool includeDetail, bool include
#endif
var ex = new RedisConnectionException(ConnectionFailureType.UnableToResolvePhysicalConnection, exceptionmessage.ToString(), innerException, message?.Status ?? CommandStatus.Unknown);
if (includeDetail)
{
AddDetail(ex, message, server, commandLabel);
......@@ -145,7 +142,7 @@ internal static Exception NoConnectionAvailable(bool includeDetail, bool include
internal static Exception PopulateInnerExceptions(ServerEndPoint[] serverSnapshot)
{
List<Exception> innerExceptions = new List<Exception>();
var innerExceptions = new List<Exception>();
if (serverSnapshot != null)
{
if (serverSnapshot.Length > 0 && serverSnapshot[0].Multiplexer.LastException != null)
......@@ -180,11 +177,11 @@ internal static Exception NotSupported(bool includeDetail, RedisCommand command)
if (includeDetail) AddDetail(ex, null, null, s);
return ex;
}
internal static Exception NoCursor(RedisCommand command)
{
string s = GetLabel(false, command, null);
var ex = new RedisCommandException("Command cannot be used with a cursor: " + s);
return ex;
return new RedisCommandException("Command cannot be used with a cursor: " + s);
}
internal static Exception Timeout(bool includeDetail, string errorMessage, Message message, ServerEndPoint server)
......@@ -203,17 +200,21 @@ private static void AddDetail(Exception exception, Message message, ServerEndPoi
exception.Data.Add(DataCommandKey, message.CommandAndKey);
exception.Data.Add(DataSentStatusKey, message.Status);
}
else if (label != null) exception.Data.Add(DataCommandKey, label);
else if (label != null)
{
exception.Data.Add(DataCommandKey, label);
}
if (server != null) exception.Data.Add(DataServerKey, Format.ToString(server.EndPoint));
}
}
static string GetLabel(bool includeDetail, RedisCommand command, Message message)
private static string GetLabel(bool includeDetail, RedisCommand command, Message message)
{
return message == null ? command.ToString() : (includeDetail ? message.CommandAndKey : message.Command.ToString());
}
static string GetLabel(bool includeDetail, string command, Message message)
private static string GetLabel(bool includeDetail, string command, Message message)
{
return message == null ? command : (includeDetail ? message.CommandAndKey : message.Command.ToString());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment