From 509cc5b974b98a1c021670bd4b637b59743d166b Mon Sep 17 00:00:00 2001 From: Yang Chun Ung Date: Wed, 3 Jul 2024 18:31:59 +0900 Subject: [PATCH] Avoid SerializationException when Exception deserialize --- .Lib9c.Tests/Action/ExceptionTest.cs | 11 +++++++++++ .../AdventureBoss/AlreadyClaimedException.cs | 9 +++++++++ .../AdventureBoss/ClaimExpiredException.cs | 9 +++++++++ .../AdventureBoss/InsufficientStakingException.cs | 9 +++++++++ .../InvalidAdventureBossSeasonException.cs | 8 ++++++++ .../AdventureBoss/InvalidBountyException.cs | 9 +++++++++ .../MaxInvestmentCountExceededException.cs | 9 +++++++++ .../AdventureBoss/PreviousBountyException.cs | 9 +++++++++ .../AdventureBoss/SeasonInProgressException.cs | 9 +++++++++ Lib9c/Action/Exceptions/EmptyRewardException.cs | 12 ++++++++++++ 10 files changed, 94 insertions(+) diff --git a/.Lib9c.Tests/Action/ExceptionTest.cs b/.Lib9c.Tests/Action/ExceptionTest.cs index 512c91da3d..5c76140980 100644 --- a/.Lib9c.Tests/Action/ExceptionTest.cs +++ b/.Lib9c.Tests/Action/ExceptionTest.cs @@ -8,6 +8,8 @@ namespace Lib9c.Tests.Action using MessagePack; using MessagePack.Resolvers; using Nekoyume.Action; + using Nekoyume.Action.Exceptions; + using Nekoyume.Action.Exceptions.AdventureBoss; using Nekoyume.Exceptions; using Nekoyume.Model.State; using Nekoyume.TableData; @@ -73,6 +75,15 @@ public ExceptionTest() [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))] public void Exception_Serializable(Type excType) { if (Activator.CreateInstance(excType, "for testing") is Exception exc) diff --git a/Lib9c/Action/Exceptions/AdventureBoss/AlreadyClaimedException.cs b/Lib9c/Action/Exceptions/AdventureBoss/AlreadyClaimedException.cs index c755526f0d..9b1f4eb25d 100644 --- a/Lib9c/Action/Exceptions/AdventureBoss/AlreadyClaimedException.cs +++ b/Lib9c/Action/Exceptions/AdventureBoss/AlreadyClaimedException.cs @@ -1,10 +1,19 @@ using System; +using System.Runtime.Serialization; namespace Nekoyume.Action.Exceptions.AdventureBoss { [Serializable] public class AlreadyClaimedException : Exception { + public AlreadyClaimedException() + { + } + + protected AlreadyClaimedException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } + public AlreadyClaimedException(string msg) : base(msg) { } diff --git a/Lib9c/Action/Exceptions/AdventureBoss/ClaimExpiredException.cs b/Lib9c/Action/Exceptions/AdventureBoss/ClaimExpiredException.cs index aadabddbca..dd549334b2 100644 --- a/Lib9c/Action/Exceptions/AdventureBoss/ClaimExpiredException.cs +++ b/Lib9c/Action/Exceptions/AdventureBoss/ClaimExpiredException.cs @@ -1,10 +1,19 @@ using System; +using System.Runtime.Serialization; namespace Nekoyume.Action.Exceptions.AdventureBoss { [Serializable] public class ClaimExpiredException : Exception { + public ClaimExpiredException() + { + } + + protected ClaimExpiredException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } + public ClaimExpiredException(string msg) : base(msg) { } diff --git a/Lib9c/Action/Exceptions/AdventureBoss/InsufficientStakingException.cs b/Lib9c/Action/Exceptions/AdventureBoss/InsufficientStakingException.cs index 3394f4701e..1990c1e0bb 100644 --- a/Lib9c/Action/Exceptions/AdventureBoss/InsufficientStakingException.cs +++ b/Lib9c/Action/Exceptions/AdventureBoss/InsufficientStakingException.cs @@ -1,10 +1,19 @@ using System; +using System.Runtime.Serialization; namespace Nekoyume.Action.Exceptions.AdventureBoss { [Serializable] public class InsufficientStakingException : Exception { + public InsufficientStakingException() + { + } + + protected InsufficientStakingException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } + public InsufficientStakingException(string msg) : base(msg) { } diff --git a/Lib9c/Action/Exceptions/AdventureBoss/InvalidAdventureBossSeasonException.cs b/Lib9c/Action/Exceptions/AdventureBoss/InvalidAdventureBossSeasonException.cs index 76fa857d8d..be52814399 100644 --- a/Lib9c/Action/Exceptions/AdventureBoss/InvalidAdventureBossSeasonException.cs +++ b/Lib9c/Action/Exceptions/AdventureBoss/InvalidAdventureBossSeasonException.cs @@ -1,10 +1,18 @@ using System; +using System.Runtime.Serialization; namespace Nekoyume.Action.Exceptions.AdventureBoss { [Serializable] public class InvalidAdventureBossSeasonException : Exception { + public InvalidAdventureBossSeasonException() + { + } + + protected InvalidAdventureBossSeasonException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } public InvalidAdventureBossSeasonException(string message) : base(message) { diff --git a/Lib9c/Action/Exceptions/AdventureBoss/InvalidBountyException.cs b/Lib9c/Action/Exceptions/AdventureBoss/InvalidBountyException.cs index d9999f1451..caf034bd6c 100644 --- a/Lib9c/Action/Exceptions/AdventureBoss/InvalidBountyException.cs +++ b/Lib9c/Action/Exceptions/AdventureBoss/InvalidBountyException.cs @@ -1,10 +1,19 @@ using System; +using System.Runtime.Serialization; namespace Nekoyume.Action.Exceptions.AdventureBoss { [Serializable] public class InvalidBountyException : Exception { + public InvalidBountyException() + { + } + + protected InvalidBountyException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } + public InvalidBountyException(string msg) : base(msg) { } diff --git a/Lib9c/Action/Exceptions/AdventureBoss/MaxInvestmentCountExceededException.cs b/Lib9c/Action/Exceptions/AdventureBoss/MaxInvestmentCountExceededException.cs index 6212609ee8..4372fc93a9 100644 --- a/Lib9c/Action/Exceptions/AdventureBoss/MaxInvestmentCountExceededException.cs +++ b/Lib9c/Action/Exceptions/AdventureBoss/MaxInvestmentCountExceededException.cs @@ -1,10 +1,19 @@ using System; +using System.Runtime.Serialization; namespace Nekoyume.Action.Exceptions.AdventureBoss { [Serializable] public class MaxInvestmentCountExceededException : Exception { + public MaxInvestmentCountExceededException() + { + } + + protected MaxInvestmentCountExceededException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } + public MaxInvestmentCountExceededException(string message) : base(message) { } diff --git a/Lib9c/Action/Exceptions/AdventureBoss/PreviousBountyException.cs b/Lib9c/Action/Exceptions/AdventureBoss/PreviousBountyException.cs index 6a030a3069..e38eaf9360 100644 --- a/Lib9c/Action/Exceptions/AdventureBoss/PreviousBountyException.cs +++ b/Lib9c/Action/Exceptions/AdventureBoss/PreviousBountyException.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.Serialization; namespace Nekoyume.Action.Exceptions.AdventureBoss { @@ -8,5 +9,13 @@ public class PreviousBountyException : Exception public PreviousBountyException(string msg) : base(msg) { } + + public PreviousBountyException() + { + } + + protected PreviousBountyException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } } } diff --git a/Lib9c/Action/Exceptions/AdventureBoss/SeasonInProgressException.cs b/Lib9c/Action/Exceptions/AdventureBoss/SeasonInProgressException.cs index c93fc06eb6..282f054ee8 100644 --- a/Lib9c/Action/Exceptions/AdventureBoss/SeasonInProgressException.cs +++ b/Lib9c/Action/Exceptions/AdventureBoss/SeasonInProgressException.cs @@ -1,10 +1,19 @@ using System; +using System.Runtime.Serialization; namespace Nekoyume.Action.Exceptions.AdventureBoss { [Serializable] public class SeasonInProgressException : Exception { + public SeasonInProgressException() + { + } + + protected SeasonInProgressException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } + public SeasonInProgressException(string msg) : base(msg) { } diff --git a/Lib9c/Action/Exceptions/EmptyRewardException.cs b/Lib9c/Action/Exceptions/EmptyRewardException.cs index 0e128d3910..d56a5fda20 100644 --- a/Lib9c/Action/Exceptions/EmptyRewardException.cs +++ b/Lib9c/Action/Exceptions/EmptyRewardException.cs @@ -1,12 +1,24 @@ using System; +using System.Runtime.Serialization; namespace Nekoyume.Action.Exceptions { [Serializable] public class EmptyRewardException : Exception { + public EmptyRewardException() + { + } + public EmptyRewardException(string msg) : base(msg) { } + + protected EmptyRewardException( + SerializationInfo info, + StreamingContext context) + : base(info, context) + { + } } }