@@ -40,7 +40,9 @@ public abstract class WitnessCondition : IInteroperable, ISerializable
4040
4141 void ISerializable . Deserialize ( ref MemoryReader reader )
4242 {
43- if ( reader . ReadByte ( ) != ( byte ) Type ) throw new FormatException ( ) ;
43+ var readType = reader . ReadByte ( ) ;
44+ if ( readType != ( byte ) Type )
45+ throw new FormatException ( $ "Read type({ readType } ) does not match WitnessConditionType({ Type } )") ;
4446 DeserializeWithoutType ( ref reader , MaxNestingDepth ) ;
4547 }
4648
@@ -66,10 +68,11 @@ protected static WitnessCondition[] DeserializeConditions(ref MemoryReader reade
6668 /// <returns>The deserialized <see cref="WitnessCondition"/>.</returns>
6769 public static WitnessCondition DeserializeFrom ( ref MemoryReader reader , int maxNestDepth )
6870 {
69- if ( maxNestDepth <= 0 ) throw new FormatException ( ) ;
71+ if ( maxNestDepth <= 0 )
72+ throw new FormatException ( $ "`maxNestDepth`({ maxNestDepth } ) in WitnessCondition is out of range (min:1)") ;
7073 WitnessConditionType type = ( WitnessConditionType ) reader . ReadByte ( ) ;
7174 if ( ReflectionCache < WitnessConditionType > . CreateInstance ( type ) is not WitnessCondition condition )
72- throw new FormatException ( ) ;
75+ throw new FormatException ( $ "Invalid WitnessConditionType( { type } )" ) ;
7376 condition . DeserializeWithoutType ( ref reader , maxNestDepth ) ;
7477 return condition ;
7578 }
@@ -110,10 +113,11 @@ void ISerializable.Serialize(BinaryWriter writer)
110113 /// <returns>The converted <see cref="WitnessCondition"/>.</returns>
111114 public static WitnessCondition FromJson ( JObject json , int maxNestDepth )
112115 {
113- if ( maxNestDepth <= 0 ) throw new FormatException ( ) ;
116+ if ( maxNestDepth <= 0 )
117+ throw new FormatException ( $ "`maxNestDepth`({ maxNestDepth } ) in WitnessCondition is out of range (min:1)") ;
114118 WitnessConditionType type = Enum . Parse < WitnessConditionType > ( json [ "type" ] . GetString ( ) ) ;
115119 if ( ReflectionCache < WitnessConditionType > . CreateInstance ( type ) is not WitnessCondition condition )
116- throw new FormatException ( "Invalid WitnessConditionType. " ) ;
120+ throw new FormatException ( $ "Invalid WitnessConditionType( { type } ) ") ;
117121 condition . ParseJson ( json , maxNestDepth ) ;
118122 return condition ;
119123 }
0 commit comments