@@ -2,7 +2,6 @@ use crate::{
22 codecs:: DecodeV2 ,
33 core:: util:: { PartialBuffer , WriteBuffer } ,
44} ;
5-
65use std:: { io:: Result , ops:: ControlFlow } ;
76
87#[ derive( Debug ) ]
@@ -11,6 +10,7 @@ enum State {
1110 Flushing ,
1211 Done ,
1312 Next ,
13+ Error ( std:: io:: Error ) ,
1414}
1515
1616#[ derive( Debug ) ]
@@ -54,7 +54,14 @@ impl Decoder {
5454 Ok ( true ) => State :: Flushing ,
5555 // ignore the first error, occurs when input is empty
5656 // but we need to run decode to flush
57- Err ( err) if !first => return ControlFlow :: Break ( Err ( err) ) ,
57+ Err ( err) if !first => {
58+ self . state = State :: Error ( err) ;
59+ if output. written_len ( ) > 0 {
60+ return ControlFlow :: Break ( Ok ( ( ) ) ) ;
61+ } else {
62+ continue ;
63+ }
64+ }
5865 // poll for more data for the next decode
5966 _ => break ,
6067 }
@@ -66,7 +73,12 @@ impl Decoder {
6673 Ok ( true ) => {
6774 if self . multiple_members {
6875 if let Err ( err) = decoder. reinit ( ) {
69- return ControlFlow :: Break ( Err ( err) ) ;
76+ self . state = State :: Error ( err) ;
77+ if output. written_len ( ) > 0 {
78+ return ControlFlow :: Break ( Ok ( ( ) ) ) ;
79+ } else {
80+ continue ;
81+ }
7082 }
7183
7284 // The decode stage might consume all the input,
@@ -78,7 +90,14 @@ impl Decoder {
7890 }
7991 }
8092 Ok ( false ) => State :: Flushing ,
81- Err ( err) => return ControlFlow :: Break ( Err ( err) ) ,
93+ Err ( err) => {
94+ self . state = State :: Error ( err) ;
95+ if output. written_len ( ) > 0 {
96+ return ControlFlow :: Break ( Ok ( ( ) ) ) ;
97+ } else {
98+ continue ;
99+ }
100+ }
82101 }
83102 }
84103
@@ -95,6 +114,13 @@ impl Decoder {
95114 State :: Decoding
96115 }
97116 }
117+
118+ State :: Error ( _) => {
119+ let State :: Error ( err) = std:: mem:: replace ( & mut self . state , State :: Done ) else {
120+ unreachable ! ( )
121+ } ;
122+ return ControlFlow :: Break ( Err ( err) ) ;
123+ }
98124 } ;
99125
100126 if output. has_no_spare_space ( ) {
0 commit comments