File tree 2 files changed +16
-11
lines changed
2 files changed +16
-11
lines changed Original file line number Diff line number Diff line change @@ -562,10 +562,12 @@ pub mod reader {
562
562
f: |& mut Decoder < ' doc > | -> DecodeResult < T > ) -> DecodeResult < T > {
563
563
debug ! ( "read_tuple()" ) ;
564
564
self . read_seq( |d, len| {
565
- assert ! ( len == tuple_len,
566
- "expected tuple of length `{}`, found tuple \
567
- of length `{}`", tuple_len, len) ;
568
- f( d)
565
+ if len == tuple_len {
566
+ f( d)
567
+ } else {
568
+ Err ( Expected ( format ! ( "Expected tuple of length `{}`, \
569
+ found tuple of length `{}`", tuple_len, len) ) )
570
+ }
569
571
} )
570
572
}
571
573
Original file line number Diff line number Diff line change @@ -2153,13 +2153,17 @@ impl ::Decoder<DecoderError> for Decoder {
2153
2153
Ok ( value)
2154
2154
}
2155
2155
2156
- fn read_tuple < T > ( & mut self , tuple_len : uint , f: |& mut Decoder | -> DecodeResult < T > ) -> DecodeResult < T > {
2156
+ fn read_tuple < T > ( & mut self ,
2157
+ tuple_len : uint ,
2158
+ f: |& mut Decoder | -> DecodeResult < T > )
2159
+ -> DecodeResult < T > {
2157
2160
debug ! ( "read_tuple()" ) ;
2158
2161
self . read_seq( |d, len| {
2159
- assert ! ( len == tuple_len,
2160
- "expected tuple of length `{}`, found tuple \
2161
- of length `{}`", tuple_len, len) ;
2162
- f( d)
2162
+ if len == tuple_len {
2163
+ f( d)
2164
+ } else {
2165
+ Err ( ExpectedError ( format ! ( "Tuple{}" , tuple_len) , format ! ( "Tuple{}" , len) ) )
2166
+ }
2163
2167
} )
2164
2168
}
2165
2169
@@ -2893,9 +2897,8 @@ mod tests {
2893
2897
}
2894
2898
2895
2899
#[ test]
2896
- #[ should_fail]
2897
2900
fn test_decode_tuple_malformed_length ( ) {
2898
- let _ = super :: decode :: < ( uint , uint ) > ( "[1, 2, 3]" ) ;
2901
+ assert ! ( super :: decode:: <( uint, uint) >( "[1, 2, 3]" ) . is_err ( ) ) ;
2899
2902
}
2900
2903
2901
2904
#[ test]
You can’t perform that action at this time.
0 commit comments