diff --git a/.Lib9c.Tests/Action/ExceptionTest.cs b/.Lib9c.Tests/Action/ExceptionTest.cs index ffb760d85e..6085d1ad1f 100644 --- a/.Lib9c.Tests/Action/ExceptionTest.cs +++ b/.Lib9c.Tests/Action/ExceptionTest.cs @@ -1,19 +1,27 @@ namespace Lib9c.Tests.Action { using System; + using System.Collections.Generic; + using System.Collections.Immutable; using System.IO; + using System.Linq; using System.Runtime.Serialization.Formatters.Binary; + using System.Security.Cryptography; + using Bencodex.Types; using Lib9c.Formatters; + using Libplanet.Action; + using Libplanet.Blockchain.Renderers.Debug; + using Libplanet.Common; using Libplanet.Crypto; + using Libplanet.Types.Assets; + using Libplanet.Types.Blocks; + using Libplanet.Types.Evidence; + using Libplanet.Types.Tx; using MessagePack; using MessagePack.Resolvers; + using Nekoyume; using Nekoyume.Action; - using Nekoyume.Action.Exceptions; - using Nekoyume.Action.Exceptions.AdventureBoss; - using Nekoyume.Action.Exceptions.Arena; - using Nekoyume.Exceptions; using Nekoyume.Model.State; - using Nekoyume.TableData; using Xunit; public class ExceptionTest @@ -28,96 +36,227 @@ public ExceptionTest() MessagePackSerializer.DefaultOptions = options; } - [Theory] - [InlineData(typeof(InvalidTradableIdException))] - [InlineData(typeof(AlreadyReceivedException))] - [InlineData(typeof(ArenaNotEndedException))] - [InlineData(typeof(AvatarIndexAlreadyUsedException))] - [InlineData(typeof(FailedLoadStateException))] - [InlineData(typeof(InvalidNamePatternException))] - [InlineData(typeof(CombinationSlotResultNullException))] - [InlineData(typeof(CombinationSlotUnlockException))] - [InlineData(typeof(NotEnoughMaterialException))] - [InlineData(typeof(InvalidPriceException))] - [InlineData(typeof(ItemDoesNotExistException))] - [InlineData(typeof(EquipmentLevelExceededException))] - [InlineData(typeof(DuplicateMaterialException))] - [InlineData(typeof(InvalidMaterialException))] - [InlineData(typeof(ConsumableSlotOutOfRangeException))] - [InlineData(typeof(ConsumableSlotUnlockException))] - [InlineData(typeof(InvalidItemTypeException))] - [InlineData(typeof(InvalidRedeemCodeException))] - [InlineData(typeof(DuplicateRedeemException))] - [InlineData(typeof(SheetRowValidateException))] - [InlineData(typeof(ShopItemExpiredException))] - [InlineData(typeof(InvalidMonsterCollectionRoundException))] - [InlineData(typeof(MonsterCollectionExpiredException))] - [InlineData(typeof(InvalidLevelException))] - [InlineData(typeof(ActionPointExceededException))] - [InlineData(typeof(InvalidItemCountException))] - [InlineData(typeof(DuplicateOrderIdException))] - [InlineData(typeof(OrderIdDoesNotExistException))] - [InlineData(typeof(ActionObsoletedException))] - [InlineData(typeof(FailedLoadSheetException))] - [InlineData(typeof(InvalidEquipmentException))] - [InlineData(typeof(AlreadyRecipeUnlockedException))] - [InlineData(typeof(InvalidRecipeIdException))] - [InlineData(typeof(AlreadyWorldUnlockedException))] - [InlineData(typeof(InvalidActionFieldException))] - [InlineData(typeof(NotEnoughEventDungeonTicketsException))] - [InlineData(typeof(InvalidClaimException))] - [InlineData(typeof(RequiredBlockIntervalException))] - [InlineData(typeof(ActionUnavailableException))] - [InlineData(typeof(InvalidTransferCurrencyException))] - [InlineData(typeof(InvalidCurrencyException))] - [InlineData(typeof(InvalidProductTypeException))] - [InlineData(typeof(ProductNotFoundException))] - [InlineData(typeof(AlreadyContractedException))] - [InlineData(typeof(ItemNotFoundException))] - [InlineData(typeof(NotEnoughItemException))] - [InlineData(typeof(StateNullException))] - [InlineData(typeof(AlreadyClaimedException))] - [InlineData(typeof(ClaimExpiredException))] - [InlineData(typeof(InsufficientStakingException))] - [InlineData(typeof(InvalidAdventureBossSeasonException))] - [InlineData(typeof(InvalidBountyException))] - [InlineData(typeof(MaxInvestmentCountExceededException))] - [InlineData(typeof(PreviousBountyException))] - [InlineData(typeof(SeasonInProgressException))] - [InlineData(typeof(EmptyRewardException))] - [InlineData(typeof(UnsupportedStateException))] - [InlineData(typeof(AlreadyJoinedArenaException))] - public void Exception_Serializable(Type excType) + /// + /// Get all exceptions defined in the Libplanet namespace. + /// + /// Enumerable object array that contain an exception object. + public static IEnumerable GetLibplanetExceptions() { - if (Activator.CreateInstance(excType, "for testing") is Exception exc) + var t = typeof(Exception); + var exceptions = AppDomain.CurrentDomain.GetAssemblies() + .SelectMany(e => e.GetTypes()) + .Where(e => + e.Namespace is not null && + e.Namespace.StartsWith("Libplanet") && + !e.IsAbstract && + e.IsClass && + e.IsAssignableTo(t)) + .ToArray(); + foreach (var e in exceptions) { - AssertException(excType, exc); + if (e == typeof(InvalidBlockProtocolVersionException) || + e == typeof(InvalidBlockStateRootHashException) || + e == typeof(DuplicateVoteException)) + { + // FIXME: + // MessagePack.MessagePackSerializationException: Failed to serialize System.Exception value. + continue; + } + + yield return new object[] { e, }; } - else + } + + /// + /// Get all exceptions defined in the Lib9c namespace. + /// + /// Enumerable object array that contain an exception object. + public static IEnumerable GetLib9cExceptions() + { + var t = typeof(Exception); + var exceptions = AppDomain.CurrentDomain.GetAssemblies() + .SelectMany(e => e.GetTypes()) + .Where(e => + e.Namespace is not null && + e.Namespace.StartsWith("Nekoyume") && + !e.IsAbstract && + e.IsClass && + e.IsAssignableTo(t)) + .ToArray(); + foreach (var e in exceptions) { - throw new InvalidCastException(); + yield return new object[] { e, }; } } /// - /// Libplanet Exception을 수정하기 위한 임시 테스트 코드입니다 - /// TODO: Libplanet Exception을 수정하고 테스트 코드 케이스를 추가해야 합니다 + /// Tests weather Libplanet and Lib9c exceptions are serializable using MessagePack. /// - /// 예외타입. + /// The type of the exception being tested. [Theory] - [InlineData(typeof(Libplanet.Action.State.InsufficientBalanceException))] - public void Libplanet_Exception_Serializable(Type excType) + [MemberData(nameof(GetLibplanetExceptions))] + [MemberData(nameof(GetLib9cExceptions))] + public void Exception_Serializable(Type excType) { - // TODO: 테스트 받는 방식 수정 - var customAddress = new Address("399bddF9F7B6d902ea27037B907B2486C9910730"); - var customFav = new Libplanet.Types.Assets.FungibleAssetValue(Currencies.Crystal); - if (Activator.CreateInstance(excType, "for testing", customAddress, customFav) is Exception exc) + var constructorTuples = excType.GetConstructors() + .Select(e => (constructorInfo: e, parameters: e.GetParameters())) + .OrderBy(tuple => tuple.parameters.Length); + foreach (var (constructorInfo, parameters) in constructorTuples) { - AssertException(excType, exc); + var parametersLength = parameters.Length; + if (parametersLength == 0) + { + AssertException((Exception)constructorInfo.Invoke(Array.Empty())); + return; + } + + var found = true; + var parameterValues = new List(); + for (var i = 0; i < parametersLength; i++) + { + if (TryGetDefaultValue(parameters[i].ParameterType, out var value)) + { + parameterValues.Add(value); + } + else + { + found = false; + break; + } + } + + if (!found) + { + continue; + } + + AssertException((Exception)constructorInfo.Invoke(parameterValues.ToArray())); + return; } - else + + throw new InvalidOperationException($"No suitable constructor found for {excType.FullName}."); + + bool TryGetDefaultValue(Type type, out object value) { - throw new InvalidCastException(); + if (Nullable.GetUnderlyingType(type) != null) + { + value = null; + return true; + } + + if (type.IsClass) + { + value = null; + return true; + } + + if (type == typeof(bool)) + { + value = default(bool); + return true; + } + + if (type == typeof(int)) + { + value = default(int); + return true; + } + + if (type == typeof(long)) + { + value = default(long); + return true; + } + + if (type == typeof(string)) + { + value = "for testing"; + return true; + } + + if (type.IsAssignableTo(typeof(Exception))) + { + value = null; + return true; + } + + if (type == typeof(Guid)) + { + value = Guid.NewGuid(); + return true; + } + + if (type == typeof(HashDigest)) + { + value = HashDigest.FromString("baa2081d3b485ef2906c95a3965531ec750a74cfaefe91d0c3061865608b426c"); + return true; + } + + if (type == typeof(ImmutableArray)) + { + value = ImmutableArray.Empty; + return true; + } + + if (type == typeof(IImmutableSet)) + { + value = ImmutableHashSet.Empty; + return true; + } + + if (type == typeof(IReadOnlyList)) + { + value = new List(); + return true; + } + + if (type == typeof(IAction)) + { + value = new DailyReward + { + avatarAddress = Addresses.Agent, + }; + return true; + } + + if (type == typeof(IValue)) + { + value = Bencodex.Types.Null.Value; + return true; + } + + if (type == typeof(Address)) + { + value = Nekoyume.Addresses.Admin; + return true; + } + + if (type == typeof(Currency)) + { + value = Currencies.Crystal; + return true; + } + + if (type == typeof(FungibleAssetValue)) + { + value = FungibleAssetValue.Parse(Currencies.Crystal, "1"); + return true; + } + + if (type == typeof(BlockHash)) + { + value = BlockHash.FromString("4582250d0da33b06779a8475d283d5dd210c683b9b999d74d03fac4f58fa6bce"); + return true; + } + + if (type == typeof(TxId)) + { + value = TxId.FromHex("300826da62b595d8cd663dadf04995a7411534d1cdc17dac75ce88754472f774"); + return true; + } + + value = null; + return false; } } @@ -156,10 +295,10 @@ public void AdminPermissionExceptionSerializable() private static void AssertException(Exception exc) where T : Exception { - AssertException(typeof(T), exc); + AssertException(exc); } - private static void AssertException(Type type, Exception exc) + private static void AssertException(Exception exc) { var b = MessagePackSerializer.Serialize(exc); var des = MessagePackSerializer.Deserialize(b); diff --git a/Lib9c/Action/ActivatedAccountsDoesNotExistsException.cs b/Lib9c/Action/ActivatedAccountsDoesNotExistsException.cs index e1b867e8fd..fabe4e5ca6 100644 --- a/Lib9c/Action/ActivatedAccountsDoesNotExistsException.cs +++ b/Lib9c/Action/ActivatedAccountsDoesNotExistsException.cs @@ -10,6 +10,10 @@ public ActivatedAccountsDoesNotExistsException() { } + public ActivatedAccountsDoesNotExistsException(string message) : base(message) + { + } + public ActivatedAccountsDoesNotExistsException( SerializationInfo info, StreamingContext context ) : base(info, context) diff --git a/Lib9c/Action/ActivationException.cs b/Lib9c/Action/ActivationException.cs index 2dc8f5c8ce..d5c5e854b7 100644 --- a/Lib9c/Action/ActivationException.cs +++ b/Lib9c/Action/ActivationException.cs @@ -8,7 +8,11 @@ public abstract class ActivationException : Exception protected ActivationException() { } - + + protected ActivationException(string message) : base(message) + { + } + protected ActivationException(SerializationInfo info, StreamingContext context) : base(info, context) { diff --git a/Lib9c/Action/BalanceDoesNotExistsException.cs b/Lib9c/Action/BalanceDoesNotExistsException.cs index fa7f9ee682..3499dcdc83 100644 --- a/Lib9c/Action/BalanceDoesNotExistsException.cs +++ b/Lib9c/Action/BalanceDoesNotExistsException.cs @@ -8,17 +8,24 @@ namespace Nekoyume.Action [Serializable] public class BalanceDoesNotExistsException : Exception { + public Address Address { get; } + public Currency Currency { get; } + public BalanceDoesNotExistsException(Address address, Currency currency) { Address = address; Currency = currency; } + public BalanceDoesNotExistsException(string message) : base(message) + { + } + protected BalanceDoesNotExistsException(SerializationInfo info, StreamingContext context) : base(info, context) { - Address = (Address) info.GetValue(nameof(Address), typeof(Address)); - Currency = (Currency) info.GetValue(nameof(Currency), typeof(Currency)); + Address = (Address)info.GetValue(nameof(Address), typeof(Address)); + Currency = (Currency)info.GetValue(nameof(Currency), typeof(Currency)); } public override void GetObjectData(SerializationInfo info, StreamingContext context) @@ -27,8 +34,5 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont info.AddValue(nameof(Address), Address); info.AddValue(nameof(Currency), Currency); } - - public Address Address { get; } - public Currency Currency { get; } } } diff --git a/Lib9c/Action/InvalidMinterException.cs b/Lib9c/Action/InvalidMinterException.cs index cf70e66784..d6d0362b4f 100644 --- a/Lib9c/Action/InvalidMinterException.cs +++ b/Lib9c/Action/InvalidMinterException.cs @@ -16,12 +16,15 @@ public InvalidMinterException() { } - public InvalidMinterException(Address signer) { _signer = signer; } + public InvalidMinterException(string message) : base(message) + { + } + protected InvalidMinterException(SerializationInfo info, StreamingContext context) : base(info, context) { diff --git a/Lib9c/Action/InvalidSignatureException.cs b/Lib9c/Action/InvalidSignatureException.cs index d44f5bf9e2..91583fdddf 100644 --- a/Lib9c/Action/InvalidSignatureException.cs +++ b/Lib9c/Action/InvalidSignatureException.cs @@ -17,9 +17,11 @@ public InvalidSignatureException(PendingActivationState pending, byte[] signatur Signature = signature; } - public InvalidSignatureException( - SerializationInfo info, StreamingContext context - ) : base(info, context) + public InvalidSignatureException(string message) : base(message) + { + } + + public InvalidSignatureException(SerializationInfo info, StreamingContext context) : base(info, context) { byte[] rawPending = (byte[])info.GetValue(nameof(Pending), typeof(byte[])); Pending = new PendingActivationState( @@ -28,10 +30,7 @@ public InvalidSignatureException( Signature = (byte[])info.GetValue(nameof(Signature), typeof(byte[])); } - public override void GetObjectData( - SerializationInfo info, - StreamingContext context - ) + public override void GetObjectData(SerializationInfo info, StreamingContext context) { base.GetObjectData(info, context); var pendingData = Pending is null ? null : new Codec().Encode(Pending.Serialize()); diff --git a/Lib9c/Action/InvalidTransferMinterException.cs b/Lib9c/Action/InvalidTransferMinterException.cs index abba2881d3..c0c1618e1a 100644 --- a/Lib9c/Action/InvalidTransferMinterException.cs +++ b/Lib9c/Action/InvalidTransferMinterException.cs @@ -21,6 +21,10 @@ public InvalidTransferMinterException(IEnumerable
minters, Address send Recipient = recipient; } + public InvalidTransferMinterException(string message) : base(message) + { + } + protected InvalidTransferMinterException(SerializationInfo info, StreamingContext context) : base(info, context) { diff --git a/Lib9c/Action/InvalidTransferRecipientException.cs b/Lib9c/Action/InvalidTransferRecipientException.cs index a2a97e65e4..5abfb5ff8f 100644 --- a/Lib9c/Action/InvalidTransferRecipientException.cs +++ b/Lib9c/Action/InvalidTransferRecipientException.cs @@ -7,17 +7,22 @@ namespace Nekoyume.Action [Serializable] public class InvalidTransferRecipientException : Exception { - public InvalidTransferRecipientException( - Address sender, - Address recipient) + public Address Sender { get; } + + public Address Recipient { get; } + + public InvalidTransferRecipientException(Address sender, Address recipient) { Sender = sender; Recipient = recipient; } - public InvalidTransferRecipientException( - SerializationInfo info, StreamingContext context - ) : base(info, context) + public InvalidTransferRecipientException(string message) : base(message) + { + } + + public InvalidTransferRecipientException(SerializationInfo info, StreamingContext context) : + base(info, context) { Sender = (Address)info.GetValue(nameof(Sender), typeof(Address)); Recipient = (Address)info.GetValue(nameof(Recipient), typeof(Address)); @@ -29,9 +34,5 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont info.AddValue(nameof(Sender), Sender); info.AddValue(nameof(Recipient), Recipient); } - - public Address Sender { get; } - - public Address Recipient { get; } } } diff --git a/Lib9c/Action/InvalidTransferSignerException.cs b/Lib9c/Action/InvalidTransferSignerException.cs index 1309a11bbb..eb674fcd4a 100644 --- a/Lib9c/Action/InvalidTransferSignerException.cs +++ b/Lib9c/Action/InvalidTransferSignerException.cs @@ -7,19 +7,25 @@ namespace Nekoyume.Action [Serializable] public class InvalidTransferSignerException : Exception { - public InvalidTransferSignerException( - Address txSigner, - Address sender, - Address recipient) + public Address TxSigner { get; } + + public Address Sender { get; } + + public Address Recipient { get; } + + public InvalidTransferSignerException(Address txSigner, Address sender, Address recipient) { TxSigner = txSigner; Sender = sender; Recipient = recipient; } - - public InvalidTransferSignerException( - SerializationInfo info, StreamingContext context - ) : base(info, context) + + public InvalidTransferSignerException(string message) : base(message) + { + } + + public InvalidTransferSignerException(SerializationInfo info, StreamingContext context) : + base(info, context) { TxSigner = (Address)info.GetValue(nameof(TxSigner), typeof(Address)); Sender = (Address)info.GetValue(nameof(Sender), typeof(Address)); @@ -33,11 +39,5 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont info.AddValue(nameof(Sender), Sender); info.AddValue(nameof(Recipient), Recipient); } - - public Address TxSigner { get; } - - public Address Sender { get; } - - public Address Recipient { get; } } } diff --git a/Lib9c/Action/InvalidTransferUnactivatedRecipientException.cs b/Lib9c/Action/InvalidTransferUnactivatedRecipientException.cs index 84a8238505..3bf450286f 100644 --- a/Lib9c/Action/InvalidTransferUnactivatedRecipientException.cs +++ b/Lib9c/Action/InvalidTransferUnactivatedRecipientException.cs @@ -7,6 +7,10 @@ namespace Nekoyume.Action [Serializable] public class InvalidTransferUnactivatedRecipientException : Exception { + public Address Sender { get; } + + public Address Recipient { get; } + public InvalidTransferUnactivatedRecipientException( Address sender, Address recipient) @@ -15,9 +19,12 @@ public InvalidTransferUnactivatedRecipientException( Recipient = recipient; } - public InvalidTransferUnactivatedRecipientException( - SerializationInfo info, StreamingContext context - ) : base(info, context) + public InvalidTransferUnactivatedRecipientException(string message) : base(message) + { + } + + public InvalidTransferUnactivatedRecipientException(SerializationInfo info, StreamingContext context) : + base(info, context) { Sender = (Address)info.GetValue(nameof(Sender), typeof(Address)); Recipient = (Address)info.GetValue(nameof(Recipient), typeof(Address)); @@ -29,9 +36,5 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont info.AddValue(nameof(Sender), Sender); info.AddValue(nameof(Recipient), Recipient); } - - public Address Sender { get; } - - public Address Recipient { get; } } } diff --git a/Lib9c/Action/NotEnoughFungibleAssetValueException.cs b/Lib9c/Action/NotEnoughFungibleAssetValueException.cs index b94c22dba8..cbcba38674 100644 --- a/Lib9c/Action/NotEnoughFungibleAssetValueException.cs +++ b/Lib9c/Action/NotEnoughFungibleAssetValueException.cs @@ -9,9 +9,11 @@ namespace Nekoyume.Action [Serializable] public class NotEnoughFungibleAssetValueException : Exception { - public NotEnoughFungibleAssetValueException( - string message, - Exception innerException = null) : + public NotEnoughFungibleAssetValueException(string message) : base(message) + { + } + + public NotEnoughFungibleAssetValueException(string message, Exception innerException) : base(message, innerException) { } @@ -20,8 +22,8 @@ public NotEnoughFungibleAssetValueException( string addressesHex, string require, string current, - Exception innerException = null) - : this( + Exception innerException = null) : + this( $"{addressesHex}Aborted as the signer's balance is" + $" insufficient to pay entrance fee/stake: {current} < {require}.", innerException) @@ -33,8 +35,8 @@ public NotEnoughFungibleAssetValueException( string addressesHex, string require, string current, - Exception innerException = null) - : this( + Exception innerException = null) : + this( $"[{actionType}][{addressesHex}] Aborted as the signer's balance is" + $" insufficient to pay entrance fee/stake: {current} < {require}.", innerException) @@ -91,8 +93,8 @@ public NotEnoughFungibleAssetValueException( string actionType, string addressesHex, BigInteger require, - BigInteger current) - : this( + BigInteger current) : + this( actionType, addressesHex, require.ToString(CultureInfo.InvariantCulture), @@ -100,9 +102,8 @@ public NotEnoughFungibleAssetValueException( { } - public NotEnoughFungibleAssetValueException( - SerializationInfo info, - StreamingContext context) : base(info, context) + public NotEnoughFungibleAssetValueException(SerializationInfo info, StreamingContext context) : + base(info, context) { } } diff --git a/Lib9c/Action/NotEnoughRankException.cs b/Lib9c/Action/NotEnoughRankException.cs index cef42b469b..cf15d7069b 100644 --- a/Lib9c/Action/NotEnoughRankException.cs +++ b/Lib9c/Action/NotEnoughRankException.cs @@ -10,8 +10,12 @@ public NotEnoughRankException() { } - public NotEnoughRankException(SerializationInfo info, StreamingContext context) : base( - info, context) + public NotEnoughRankException(string message) : base(message) + { + } + + public NotEnoughRankException(SerializationInfo info, StreamingContext context) : + base(info, context) { } } diff --git a/Lib9c/Action/PendingActivationDoesNotExistsException.cs b/Lib9c/Action/PendingActivationDoesNotExistsException.cs index 66c7fd6631..3c57471728 100644 --- a/Lib9c/Action/PendingActivationDoesNotExistsException.cs +++ b/Lib9c/Action/PendingActivationDoesNotExistsException.cs @@ -14,20 +14,17 @@ public PendingActivationDoesNotExistsException(Address pendingAddress) PendingAddress = pendingAddress; } - public PendingActivationDoesNotExistsException( - SerializationInfo info, StreamingContext context - ) : base(info, context) + public PendingActivationDoesNotExistsException(string message) : base(message) { - PendingAddress = (Address)info.GetValue( - nameof(PendingAddress), - typeof(Address) - ); } - public override void GetObjectData( - SerializationInfo info, - StreamingContext context - ) + public PendingActivationDoesNotExistsException(SerializationInfo info, StreamingContext context) : + base(info, context) + { + PendingAddress = (Address)info.GetValue(nameof(PendingAddress), typeof(Address)); + } + + public override void GetObjectData(SerializationInfo info, StreamingContext context) { base.GetObjectData(info, context); info.AddValue(nameof(PendingAddress), PendingAddress); diff --git a/Lib9c/Action/PermissionDeniedException.cs b/Lib9c/Action/PermissionDeniedException.cs index ad76ef4e81..f76c8b46fd 100644 --- a/Lib9c/Action/PermissionDeniedException.cs +++ b/Lib9c/Action/PermissionDeniedException.cs @@ -11,12 +11,14 @@ public class PermissionDeniedException : AdminPermissionException { public Address Signer { get; } - public PermissionDeniedException(AdminState policy, Address signer) - : base(policy) + public PermissionDeniedException(AdminState policy, Address signer) : base(policy) { Signer = signer; } + public PermissionDeniedException(string message) : base(message) + { + } public PermissionDeniedException(SerializationInfo info, StreamingContext context) : base(info, context) { diff --git a/Lib9c/Action/PermissionException.cs b/Lib9c/Action/PermissionException.cs index 6fa965246d..12ceb6830d 100644 --- a/Lib9c/Action/PermissionException.cs +++ b/Lib9c/Action/PermissionException.cs @@ -10,11 +10,15 @@ public abstract class AdminPermissionException : Exception { public AdminState Policy { get; private set; } - public AdminPermissionException(AdminState policy) + protected AdminPermissionException(AdminState policy) { Policy = policy; } + protected AdminPermissionException(string message) : base(message) + { + } + protected AdminPermissionException(SerializationInfo info, StreamingContext context) { Policy = info.GetValue(nameof(Policy)); diff --git a/Lib9c/Action/PolicyExpiredException.cs b/Lib9c/Action/PolicyExpiredException.cs index c7b991e574..3be9fc6869 100644 --- a/Lib9c/Action/PolicyExpiredException.cs +++ b/Lib9c/Action/PolicyExpiredException.cs @@ -10,12 +10,15 @@ public class PolicyExpiredException : AdminPermissionException { public long BlockIndex { get; } - public PolicyExpiredException(AdminState policy, long blockIndex) - : base(policy) + public PolicyExpiredException(AdminState policy, long blockIndex) : base(policy) { BlockIndex = blockIndex; } + public PolicyExpiredException(string message) : base(message) + { + } + public PolicyExpiredException(SerializationInfo info, StreamingContext context) : base(info, context) { BlockIndex = info.GetValue(nameof(BlockIndex)); diff --git a/Lib9c/Action/RankingExceededException.cs b/Lib9c/Action/RankingExceededException.cs index 4020aace43..0d2e7165b4 100644 --- a/Lib9c/Action/RankingExceededException.cs +++ b/Lib9c/Action/RankingExceededException.cs @@ -4,14 +4,18 @@ namespace Nekoyume.Action { [Serializable] - public class RankingExceededException: InvalidOperationException + public class RankingExceededException : InvalidOperationException { public RankingExceededException() { } - protected RankingExceededException(SerializationInfo info, StreamingContext context) - : base(info, context) + public RankingExceededException(string message) : base(message) + { + } + + protected RankingExceededException(SerializationInfo info, StreamingContext context) : + base(info, context) { } } diff --git a/Lib9c/Action/TotalSupplyDoesNotExistException.cs b/Lib9c/Action/TotalSupplyDoesNotExistException.cs index 56516dc601..45958b2034 100644 --- a/Lib9c/Action/TotalSupplyDoesNotExistException.cs +++ b/Lib9c/Action/TotalSupplyDoesNotExistException.cs @@ -7,15 +7,21 @@ namespace Nekoyume.Action [Serializable] public class TotalSupplyDoesNotExistException : Exception { + public Currency Currency { get; } + public TotalSupplyDoesNotExistException(Currency currency) { Currency = currency; } - protected TotalSupplyDoesNotExistException(SerializationInfo info, StreamingContext context) - : base(info, context) + public TotalSupplyDoesNotExistException(string message) : base(message) { - Currency = (Currency) info.GetValue(nameof(Currency), typeof(Currency)); + } + + protected TotalSupplyDoesNotExistException(SerializationInfo info, StreamingContext context) : + base(info, context) + { + Currency = (Currency)info.GetValue(nameof(Currency), typeof(Currency)); } public override void GetObjectData(SerializationInfo info, StreamingContext context) @@ -23,7 +29,5 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont base.GetObjectData(info, context); info.AddValue(nameof(Currency), Currency); } - - public Currency Currency { get; } } } diff --git a/Lib9c/Battle/WeightedSelector.cs b/Lib9c/Battle/WeightedSelector.cs index c0c38bc05f..ed7c43c335 100644 --- a/Lib9c/Battle/WeightedSelector.cs +++ b/Lib9c/Battle/WeightedSelector.cs @@ -154,7 +154,11 @@ private void Validate(int count) public class InvalidCountException : InvalidOperationException { - public InvalidCountException() : base("count must be greater than 0.") + public InvalidCountException() : this("count must be greater than 0.") + { + } + + public InvalidCountException(string message) : base(message) { } } diff --git a/Lib9c/Exceptions/PetCostNotFoundException.cs b/Lib9c/Exceptions/PetCostNotFoundException.cs index 1895921e2b..88ece85c79 100644 --- a/Lib9c/Exceptions/PetCostNotFoundException.cs +++ b/Lib9c/Exceptions/PetCostNotFoundException.cs @@ -5,7 +5,11 @@ namespace Nekoyume.Exceptions [Serializable] public class PetCostNotFoundException : Exception { - public PetCostNotFoundException(string message, Exception innerException = null) : + public PetCostNotFoundException(string message) : base(message) + { + } + + public PetCostNotFoundException(string message, Exception innerException) : base(message, innerException) { } @@ -14,8 +18,8 @@ public PetCostNotFoundException( string actionType, string addressesHex, string message, - Exception innerException = null) - : base( + Exception innerException = null) : + base( $"[{actionType}][{addressesHex}] {message}", innerException) { diff --git a/Lib9c/TableData/Exceptions.cs b/Lib9c/TableData/Exceptions.cs index 990965d978..67f841068c 100644 --- a/Lib9c/TableData/Exceptions.cs +++ b/Lib9c/TableData/Exceptions.cs @@ -47,13 +47,13 @@ public SheetRowNotFoundException(string sheetName, string key) } public SheetRowNotFoundException(string sheetName, string condition, string value) : - base($"{sheetName}: {condition} - {value}") + this($"{sheetName}: {condition} - {value}") { } - public SheetRowNotFoundException(string addressesHex, string sheetName, int intKey) - : base($"{addressesHex}{sheetName}:" + - $" Key - {intKey.ToString(CultureInfo.InvariantCulture)}") + public SheetRowNotFoundException(string addressesHex, string sheetName, int intKey) : + this($"{addressesHex}{sheetName}:" + + $" Key - {intKey.ToString(CultureInfo.InvariantCulture)}") { } @@ -61,16 +61,18 @@ public SheetRowNotFoundException( string actionType, string addressesHex, string sheetName, - int intKey) - : base($"[{actionType}][{addressesHex}]{sheetName}:" + - $" Key - {intKey.ToString(CultureInfo.InvariantCulture)}") + int intKey) : + this($"[{actionType}][{addressesHex}]{sheetName}:" + + $" Key - {intKey.ToString(CultureInfo.InvariantCulture)}") { } - protected SheetRowNotFoundException( - SerializationInfo info, - StreamingContext context) - : base(info, context) + public SheetRowNotFoundException(string message) : base(message) + { + } + + protected SheetRowNotFoundException(SerializationInfo info, StreamingContext context) : + base(info, context) { } }