File tree Expand file tree Collapse file tree 2 files changed +16
-11
lines changed
Expand file tree Collapse file tree 2 files changed +16
-11
lines changed Original file line number Diff line number Diff line change @@ -562,10 +562,12 @@ pub mod reader {
562562 f: |&mut Decoder<'doc>| -> DecodeResult<T>) -> DecodeResult<T> {
563563 debug!("read_tuple()");
564564 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+ }
569571 })
570572 }
571573
Original file line number Diff line number Diff line change @@ -2153,13 +2153,17 @@ impl ::Decoder<DecoderError> for Decoder {
21532153 Ok(value)
21542154 }
21552155
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> {
21572160 debug!("read_tuple()");
21582161 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+ }
21632167 })
21642168 }
21652169
@@ -2893,9 +2897,8 @@ mod tests {
28932897 }
28942898
28952899 #[test]
2896- #[should_fail]
28972900 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() );
28992902 }
29002903
29012904 #[test]
You can’t perform that action at this time.
0 commit comments