@@ -133,8 +133,7 @@ impl TypeSerializer for UnionSerializer {
133133            extra, 
134134            & self . choices , 
135135            self . retry_with_lax_check ( ) , 
136-         ) 
137-         . unwrap ( ) 
136+         ) ?
138137    } 
139138
140139    fn  json_key < ' a > ( & self ,  key :  & ' a  Bound < ' _ ,  PyAny > ,  extra :  & Extra )  -> PyResult < Cow < ' a ,  str > >  { 
@@ -144,8 +143,7 @@ impl TypeSerializer for UnionSerializer {
144143            extra, 
145144            & self . choices , 
146145            self . retry_with_lax_check ( ) , 
147-         ) 
148-         . unwrap ( ) 
146+         ) ?
149147    } 
150148
151149    fn  serde_serialize < S :  serde:: ser:: Serializer > ( 
@@ -156,7 +154,7 @@ impl TypeSerializer for UnionSerializer {
156154        exclude :  Option < & Bound < ' _ ,  PyAny > > , 
157155        extra :  & Extra , 
158156    )  -> Result < S :: Ok ,  S :: Error >  { 
159-         union_serialize ( 
157+         match   union_serialize ( 
160158            |comb_serializer,  new_extra| comb_serializer. to_python ( value,  include,  exclude,  new_extra) , 
161159            |v| { 
162160                infer_serialize ( 
@@ -170,8 +168,15 @@ impl TypeSerializer for UnionSerializer {
170168            extra, 
171169            & self . choices , 
172170            self . retry_with_lax_check ( ) , 
173-         ) 
174-         . unwrap ( ) 
171+         )  { 
172+             Ok ( v)  => v, 
173+             // TODO: we don't expect to hit this branch, but if we do, we should change the return 
174+             // type of this function to return a PyResult... 
175+             Err ( err)  => { 
176+                 let  message = err. to_string ( ) ; 
177+                 Err ( serde:: ser:: Error :: custom ( message) ) 
178+             } 
179+         } 
175180    } 
176181
177182    fn  get_name ( & self )  -> & str  { 
@@ -267,8 +272,7 @@ impl TypeSerializer for TaggedUnionSerializer {
267272            extra, 
268273            & self . choices , 
269274            self . retry_with_lax_check ( ) , 
270-         ) 
271-         . unwrap ( ) 
275+         ) ?
272276    } 
273277
274278    fn  json_key < ' a > ( & self ,  key :  & ' a  Bound < ' _ ,  PyAny > ,  extra :  & Extra )  -> PyResult < Cow < ' a ,  str > >  { 
@@ -300,8 +304,7 @@ impl TypeSerializer for TaggedUnionSerializer {
300304            extra, 
301305            & self . choices , 
302306            self . retry_with_lax_check ( ) , 
303-         ) 
304-         . unwrap ( ) 
307+         ) ?
305308    } 
306309
307310    fn  serde_serialize < S :  serde:: ser:: Serializer > ( 
@@ -335,7 +338,7 @@ impl TypeSerializer for TaggedUnionSerializer {
335338            } 
336339        } 
337340
338-         union_serialize ( 
341+         match   union_serialize ( 
339342            |comb_serializer,  new_extra| comb_serializer. to_python ( value,  include,  exclude,  new_extra) , 
340343            |v| { 
341344                infer_serialize ( 
@@ -349,8 +352,15 @@ impl TypeSerializer for TaggedUnionSerializer {
349352            extra, 
350353            & self . choices , 
351354            self . retry_with_lax_check ( ) , 
352-         ) 
353-         . unwrap ( ) 
355+         )  { 
356+             Ok ( v)  => v, 
357+             // TODO: we don't expect to hit this branch, but if we do, we should change the return 
358+             // type of this function to return a PyResult... 
359+             Err ( err)  => { 
360+                 let  message = err. to_string ( ) ; 
361+                 Err ( serde:: ser:: Error :: custom ( message) ) 
362+             } 
363+         } 
354364    } 
355365
356366    fn  get_name ( & self )  -> & str  { 
0 commit comments