Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ public ActiveDirectoryAuthenticationTimeoutRetryState State
if (value != ActiveDirectoryAuthenticationTimeoutRetryState.Retrying
&& value != ActiveDirectoryAuthenticationTimeoutRetryState.HasLoggedIn)
{
throw new InvalidOperationException($"Cannot transit from {_state} to {value}.");
throw new InvalidOperationException(StringsHelper.GetString(Strings.SQL_ActiveDirectoryInvalidStateTransition, _state, value));
}
break;
case ActiveDirectoryAuthenticationTimeoutRetryState.Retrying:
if (value != ActiveDirectoryAuthenticationTimeoutRetryState.HasLoggedIn)
{
throw new InvalidOperationException($"Cannot transit from {_state} to {value}.");
throw new InvalidOperationException(StringsHelper.GetString(Strings.SQL_ActiveDirectoryInvalidStateTransition, _state, value));
}
break;
case ActiveDirectoryAuthenticationTimeoutRetryState.HasLoggedIn:
throw new InvalidOperationException($"Cannot transit from {_state} to {value}.");
throw new InvalidOperationException(StringsHelper.GetString(Strings.SQL_ActiveDirectoryInvalidStateTransition, _state, value));
default:
throw new InvalidOperationException($"Unsupported state: {value}.");
throw new InvalidOperationException(StringsHelper.GetString(Strings.SQL_ActiveDirectoryUnsupportedState, value));
}
if (_sqlAuthLogger.IsLoggingEnabled)
{
Expand Down Expand Up @@ -133,7 +133,7 @@ private static string GetTokenHash(SqlFedAuthToken token)

// Here we mimic how ADAL calculates hash for token. They use UTF8 instead of Unicode.
var originalTokenString = Encoding.Unicode.GetString(token.AccessToken);

var bytesInUtf8 = Encoding.UTF8.GetBytes(originalTokenString);
using (var sha256 = SHA256.Create())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,7 @@ private async Task<DbConnectionInternal> GetInternalConnection(
}
catch (ChannelClosedException)
{
//TODO: exceptions from resource file
throw new Exception("The connection pool has been shut down.");
throw new InvalidOperationException(StringsHelper.GetString(Strings.SQL_ConnectionPoolShutDown));
}

if (connection is not null && !IsLiveConnection(connection))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ internal ConnectionPoolSlots(uint fixedCapacity)
}
}

throw new InvalidOperationException("Couldn't find an empty slot.");
throw new InvalidOperationException(StringsHelper.GetString(Strings.SQL_ConnectionPoolNoEmptySlot));
}
catch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public int RequiredLength
CheckDisposed();
if (!HasDataLength)
{
throw new InvalidOperationException($"cannot get {nameof(RequiredLength)} when {nameof(HasDataLength)} is false");
throw new InvalidOperationException(StringsHelper.GetString(Strings.SQL_Packet_RequiredLengthUnavailable));
}
return TdsEnums.HEADER_LEN + _dataLength;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private static SqlRetryLogicBaseProvider ResolveRetryLogicProvider(string config

if (string.IsNullOrEmpty(retryMethod))
{
throw new ArgumentNullException($"Failed to create {nameof(SqlRetryLogicBaseProvider)} object because the {nameof(retryMethod)} value is null or empty.");
throw new ArgumentNullException(nameof(retryMethod), StringsHelper.GetString(Strings.SQLCR_RetryMethodNullOrEmpty));
}

Type type = null;
Expand Down Expand Up @@ -155,7 +155,7 @@ private static SqlRetryLogicBaseProvider ResolveRetryLogicProvider(string config
// i.e: Opening a connection or executing a command while invoking a function
// runs the application to the `TargetInvocationException`.
// And using an isolated zone like a specific AppDomain results in an infinite loop.
throw new Exception($"Exception occurred when running the `{type.FullName}.{retryMethod}()` method.", e);
throw new InvalidOperationException(StringsHelper.GetString(Strings.SQLCR_RetryMethodException, type.FullName, retryMethod), e);
}

SqlClientEventSource.Log.TryTraceEvent("<sc.{0}.{1}|INFO> Unable to resolve a valid provider; Returns `null`.", TypeName, methodName);
Expand All @@ -180,7 +180,7 @@ private static object CreateInstance(
MethodInfo internalMethod = typeof(SqlConfigurableRetryFactory).GetMethod(retryMethodName);
if (internalMethod == null)
{
throw new InvalidOperationException($"Failed to resolve the '{retryMethodName}' method from `{typeof(SqlConfigurableRetryFactory).FullName}` type.");
throw new InvalidOperationException(StringsHelper.GetString(Strings.SQLCR_ResolveMethodFailed, retryMethodName, typeof(SqlConfigurableRetryFactory).FullName));
}

SqlClientEventSource.Log.TryTraceEvent("<sc.{0}.{1}|INFO> The `{2}.{3}()` method has been discovered as the `{4}` method name."
Expand All @@ -196,14 +196,14 @@ private static object CreateInstance(
MethodInfo method = type.GetMethod(retryMethodName);
if (method == null)
{
throw new InvalidOperationException($"Failed to resolve the '{retryMethodName}' method from `{type.FullName}` type.");
throw new InvalidOperationException(StringsHelper.GetString(Strings.SQLCR_ResolveMethodFailed, retryMethodName, type.FullName));
}
SqlClientEventSource.Log.TryTraceEvent("<sc.{0}.{1}|INFO> The `{2}` method metadata has been extracted from the `{3}` type by using the `{4}` method name."
, TypeName, methodName, method.Name, type.FullName, retryMethodName);

if (!typeof(SqlRetryLogicBaseProvider).IsAssignableFrom(method.ReturnType))
{
throw new InvalidCastException($"Invalid return type; Return type must be of `{typeof(SqlRetryLogicBaseProvider).FullName}` type.");
throw new InvalidCastException(StringsHelper.GetString(Strings.SQLCR_InvalidReturnType, typeof(SqlRetryLogicBaseProvider).FullName));
}
SqlClientEventSource.Log.TryTraceEvent("<sc.{0}.{1}|INFO> The return type of the `{2}.{3}()` method is valid."
, TypeName, methodName, type.FullName, method.Name);
Expand Down Expand Up @@ -243,8 +243,7 @@ private static object[] PrepareParamValues(ParameterInfo[] parameterInfos, SqlRe

if (!found)
{
string message = $"Failed to create {nameof(SqlRetryLogicBaseProvider)} object because of invalid {retryMethod}'s parameters." +
$"{Environment.NewLine}The function must have a paramter of type '{nameof(SqlRetryLogicOption)}'.";
string message = StringsHelper.GetString(Strings.SQLCR_InvalidRetryParameters, retryMethod, Environment.NewLine);
throw new InvalidOperationException(message);
}
}
Expand Down Expand Up @@ -290,8 +289,7 @@ private static object[] PrepareParamValues(ParameterInfo[] parameterInfos, SqlRe
}
else
{
string message = $"Failed to create {nameof(SqlRetryLogicBaseProvider)} object because of invalid {nameof(retryMethod)}'s parameters."
+ $"{Environment.NewLine}Parameter '{paramInfo.ParameterType.Name} {paramInfo.Name}' doesn't have default value.";
string message = StringsHelper.GetString(Strings.SQLCR_InvalidParameterNoDefault, Environment.NewLine, paramInfo.ParameterType.Name, paramInfo.Name);
throw new InvalidOperationException(message);
}
}
Expand Down Expand Up @@ -416,15 +414,15 @@ private static Type TypeResolver(Assembly arg1, string arg2, bool arg3)
{
if (result != null)
{
throw new InvalidOperationException("Sequence contains more than one matching element");
throw new InvalidOperationException(StringsHelper.GetString(Strings.SQLCR_SequenceMoreThanOneMatch));
}
result = type;
}
}
}
if (result == null)
{
throw new InvalidOperationException("Sequence contains no matching element");
throw new InvalidOperationException(StringsHelper.GetString(Strings.SQLCR_SequenceNoMatch));
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2923,7 +2923,7 @@ internal byte[] GetBytes(object o, out int maxSize)

if (maxSize < -1 || maxSize >= ushort.MaxValue)
{
throw new InvalidOperationException(o.GetType() + ": invalid Size");
throw new InvalidOperationException(StringsHelper.GetString(Strings.SQL_InvalidUdtSize, o.GetType().FullName));
}

byte[] retval;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private void SetPartialPacket(Packet packet)
{
if (_partialPacket != null && packet != null)
{
throw new InvalidOperationException("partial packet cannot be non-null when setting to non=null");
throw new InvalidOperationException(StringsHelper.GetString(Strings.SQL_Multiplexer_PartialPacketNotNull));
}
_partialPacket = packet;
}
Expand Down Expand Up @@ -488,7 +488,7 @@ out bool recurse

if (consumePartialPacket && consumeInputDirectly)
{
throw new InvalidOperationException($"MultiplexPackets cannot return both {nameof(consumePartialPacket)} and {nameof(consumeInputDirectly)}");
throw new InvalidOperationException(StringsHelper.GetString(Strings.SQL_Multiplexer_ConflictingConsumeModes));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3493,7 +3493,7 @@ internal TdsOperationStatus TryReadNetworkPacket()
#if DEBUG
if (s_failAsyncPends)
{
throw new InvalidOperationException("Attempted to pend a read when s_failAsyncPends test hook was enabled");
throw new InvalidOperationException(StringsHelper.GetString(Strings.SQL_FailAsyncPendsEnabled));
}
if (s_forceSyncOverAsyncAfterFirstPend)
{
Expand Down Expand Up @@ -4869,7 +4869,7 @@ partial void CheckDebugDataHashImpl()
{
if (Buffer != null && Read > 0)
{
throw new InvalidOperationException("Packet modification detected. Hash is null but packet contains non-null buffer");
throw new InvalidOperationException(StringsHelper.GetString(Strings.SQL_PacketHashNullWithNonNullBuffer));
}
}
else
Expand All @@ -4884,7 +4884,7 @@ partial void CheckDebugDataHashImpl()
{
if (Hash[index] != checkHash[index])
{
throw new InvalidOperationException("Packet modification detected. Hash from packet creation does not match hash from packet check");
throw new InvalidOperationException(StringsHelper.GetString(Strings.SQL_PacketHashMismatch));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public T Rent()
return item;
}

return _onCreate?.Invoke() ?? throw new InvalidOperationException("Can only rent from a pool if an onCreate delegate is available");
return _onCreate?.Invoke() ?? throw new InvalidOperationException(StringsHelper.GetString(Strings.SQL_ObjectPoolNoCreateDelegate));
}

public bool TryGet(out T item)
Expand Down
Loading
Loading