Core/Errors: Stop using System.Diagnostics.Contracts, Its just closing the server without error or warning. We now log the error and then throw a exception
This commit is contained in:
@@ -15,7 +15,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
namespace System.Collections
|
||||
{
|
||||
@@ -27,7 +26,6 @@ namespace System.Collections
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("length");
|
||||
}
|
||||
Contract.EndContractBlock();
|
||||
|
||||
_mArray = new uint[GetArrayLength(length, BitsPerInt32)];
|
||||
_mLength = length;
|
||||
@@ -47,7 +45,7 @@ namespace System.Collections
|
||||
{
|
||||
throw new ArgumentNullException("values");
|
||||
}
|
||||
Contract.EndContractBlock();
|
||||
|
||||
// this value is chosen to prevent overflow when computing m_length
|
||||
if (values.Length > UInt32.MaxValue / BitsPerInt32)
|
||||
{
|
||||
@@ -68,7 +66,6 @@ namespace System.Collections
|
||||
{
|
||||
throw new ArgumentNullException("bits");
|
||||
}
|
||||
Contract.EndContractBlock();
|
||||
|
||||
int arrayLength = GetArrayLength(bits._mLength, BitsPerInt32);
|
||||
_mArray = new uint[arrayLength];
|
||||
@@ -97,7 +94,6 @@ namespace System.Collections
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("index");
|
||||
}
|
||||
Contract.EndContractBlock();
|
||||
|
||||
return (Convert.ToInt64(_mArray[index / 32]) & (1 << (index % 32))) != 0;
|
||||
}
|
||||
@@ -108,7 +104,6 @@ namespace System.Collections
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("index");
|
||||
}
|
||||
Contract.EndContractBlock();
|
||||
|
||||
if (value)
|
||||
{
|
||||
@@ -140,7 +135,6 @@ namespace System.Collections
|
||||
throw new ArgumentNullException("value");
|
||||
if (Length != value.Length)
|
||||
throw new ArgumentException();
|
||||
Contract.EndContractBlock();
|
||||
|
||||
int ints = GetArrayLength(_mLength, BitsPerInt32);
|
||||
for (int i = 0; i < ints; i++)
|
||||
@@ -158,7 +152,6 @@ namespace System.Collections
|
||||
throw new ArgumentNullException("value");
|
||||
if (Length != value.Length)
|
||||
throw new ArgumentException();
|
||||
Contract.EndContractBlock();
|
||||
|
||||
int ints = GetArrayLength(_mLength, BitsPerInt32);
|
||||
for (int i = 0; i < ints; i++)
|
||||
@@ -176,7 +169,6 @@ namespace System.Collections
|
||||
throw new ArgumentNullException("value");
|
||||
if (Length != value.Length)
|
||||
throw new ArgumentException();
|
||||
Contract.EndContractBlock();
|
||||
|
||||
int ints = GetArrayLength(_mLength, BitsPerInt32);
|
||||
for (int i = 0; i < ints; i++)
|
||||
@@ -204,7 +196,6 @@ namespace System.Collections
|
||||
{
|
||||
get
|
||||
{
|
||||
Contract.Ensures(Contract.Result<int>() >= 0);
|
||||
return _mLength;
|
||||
}
|
||||
set
|
||||
@@ -213,7 +204,6 @@ namespace System.Collections
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("value");
|
||||
}
|
||||
Contract.EndContractBlock();
|
||||
|
||||
int newints = GetArrayLength(value, BitsPerInt32);
|
||||
if (newints > _mArray.Length || newints + ShrinkThreshold < _mArray.Length)
|
||||
@@ -255,8 +245,6 @@ namespace System.Collections
|
||||
if (array.Rank != 1)
|
||||
throw new ArgumentException();
|
||||
|
||||
Contract.EndContractBlock();
|
||||
|
||||
if (array is uint[])
|
||||
{
|
||||
Array.Copy(_mArray, 0, array, index, GetArrayLength(_mLength, BitsPerInt32));
|
||||
@@ -288,17 +276,12 @@ namespace System.Collections
|
||||
{
|
||||
get
|
||||
{
|
||||
Contract.Ensures(Contract.Result<int>() >= 0);
|
||||
|
||||
return _mLength;
|
||||
}
|
||||
}
|
||||
|
||||
public Object Clone()
|
||||
{
|
||||
Contract.Ensures(Contract.Result<Object>() != null);
|
||||
Contract.Ensures(((BitArray)Contract.Result<Object>()).Length == this.Length);
|
||||
|
||||
BitSet bitArray = new BitSet(_mArray);
|
||||
bitArray._version = _version;
|
||||
bitArray._mLength = _mLength;
|
||||
@@ -345,7 +328,7 @@ namespace System.Collections
|
||||
|
||||
private static int GetArrayLength(int n, int div)
|
||||
{
|
||||
Contract.Assert(div > 0, "GetArrayLength: div arg must be greater than 0");
|
||||
Cypher.Assert(div > 0, "GetArrayLength: div arg must be greater than 0");
|
||||
return n > 0 ? (((n - 1) / div) + 1) : 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Framework.Database
|
||||
@@ -68,7 +67,7 @@ namespace Framework.Database
|
||||
bool hasNext = _result != null;
|
||||
if (_callbacks.Count == 0)
|
||||
{
|
||||
Contract.Assert(!hasNext);
|
||||
Cypher.Assert(!hasNext);
|
||||
return QueryCallbackStatus.Completed;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2018 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
public class Cypher
|
||||
{
|
||||
public static void Assert(bool value, string message = "", [CallerMemberName]string memberName = "")
|
||||
{
|
||||
if (!value)
|
||||
{
|
||||
if (!message.IsEmpty())
|
||||
Log.outFatal(LogFilter.Server, message);
|
||||
|
||||
throw new Exception(memberName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,21 @@
|
||||
using System;
|
||||
/*
|
||||
* Copyright (C) 2012-2018 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Linq;
|
||||
|
||||
namespace Framework.Dynamic
|
||||
@@ -112,13 +111,13 @@ namespace Framework.Dynamic
|
||||
|
||||
public void ScheduleAbort()
|
||||
{
|
||||
Contract.Assert(IsRunning(), "Tried to scheduled the abortion of an event twice!");
|
||||
Cypher.Assert(IsRunning(), "Tried to scheduled the abortion of an event twice!");
|
||||
m_abortState = AbortState.Scheduled;
|
||||
}
|
||||
|
||||
public void SetAborted()
|
||||
{
|
||||
Contract.Assert(!IsAborted(), "Tried to abort an already aborted event!");
|
||||
Cypher.Assert(!IsAborted(), "Tried to abort an already aborted event!");
|
||||
m_abortState = AbortState.Aborted;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
*/
|
||||
|
||||
using Framework.Collections;
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
namespace Framework.Dynamic
|
||||
{
|
||||
@@ -42,7 +41,7 @@ namespace Framework.Dynamic
|
||||
// Create new link
|
||||
public void link(TO toObj, FROM fromObj)
|
||||
{
|
||||
Contract.Assert(fromObj != null); // fromObj MUST not be NULL
|
||||
Cypher.Assert(fromObj != null); // fromObj MUST not be NULL
|
||||
if (isValid())
|
||||
unlink();
|
||||
if (toObj != null)
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Linq;
|
||||
|
||||
namespace Framework.Dynamic
|
||||
@@ -622,7 +621,7 @@ namespace Framework.Dynamic
|
||||
{
|
||||
// This was adapted to TC to prevent static analysis tools from complaining.
|
||||
// If you encounter this assertion check if you repeat a TaskContext more then 1 time!
|
||||
Contract.Assert(!_consumed, "Bad task logic, task context was consumed already!");
|
||||
Cypher.Assert(!_consumed, "Bad task logic, task context was consumed already!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Framework.IO
|
||||
@@ -47,7 +46,6 @@ namespace Framework.IO
|
||||
if (!MoveNext(delimiters))
|
||||
return "";
|
||||
|
||||
Contract.Assume(Current != null);
|
||||
return Current;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace Framework.Networking
|
||||
@@ -25,7 +24,7 @@ namespace Framework.Networking
|
||||
{
|
||||
public virtual bool StartNetwork(string bindIp, int port, int threadCount = 1)
|
||||
{
|
||||
Contract.Assert(threadCount > 0);
|
||||
Cypher.Assert(threadCount > 0);
|
||||
|
||||
Acceptor = new AsyncAcceptor();
|
||||
if (!Acceptor.Start(bindIp, port))
|
||||
|
||||
@@ -207,7 +207,7 @@ public static class MathFunctions
|
||||
return val1 <= val2;
|
||||
default:
|
||||
// incorrect parameter
|
||||
//Contract.Assert(false);
|
||||
Cypher.Assert(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -228,7 +228,7 @@ public static class MathFunctions
|
||||
return val1 <= val2;
|
||||
default:
|
||||
// incorrect parameter
|
||||
//Contract.Assert(false);
|
||||
Cypher.Assert(false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
public class RandomHelper
|
||||
{
|
||||
@@ -70,7 +69,7 @@ public class RandomHelper
|
||||
}
|
||||
public static float FRand(float min, float max)
|
||||
{
|
||||
Contract.Assert(max >= min);
|
||||
Cypher.Assert(max >= min);
|
||||
return (float)(rand.NextDouble() * (max - min) + min);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user