File tree Expand file tree Collapse file tree 1 file changed +10
-11
lines changed Expand file tree Collapse file tree 1 file changed +10
-11
lines changed Original file line number Diff line number Diff line change @@ -262,17 +262,16 @@ mod builtins {
262
262
) ) ;
263
263
}
264
264
265
- match std:: str:: from_utf8 ( source) {
266
- Ok ( s) => Ok ( Either :: A ( vm. ctx . new_str ( s) ) ) ,
267
- Err ( err) => {
268
- let msg = format ! (
269
- "(unicode error) 'utf-8' codec can't decode byte 0x{:x?} in position {}: invalid start byte" ,
270
- source[ err. valid_up_to( ) ] ,
271
- err. valid_up_to( )
272
- ) ;
273
- Err ( vm. new_exception_msg ( vm. ctx . exceptions . syntax_error . to_owned ( ) , msg) )
274
- }
275
- }
265
+ let source = std:: str:: from_utf8 ( source) . map_err ( |err| {
266
+ let msg = format ! (
267
+ "(unicode error) 'utf-8' codec can't decode byte 0x{:x?} in position {}: invalid start byte" ,
268
+ source[ err. valid_up_to( ) ] ,
269
+ err. valid_up_to( )
270
+ ) ;
271
+
272
+ vm. new_exception_msg ( vm. ctx . exceptions . syntax_error . to_owned ( ) , msg)
273
+ } ) ?;
274
+ Ok ( Either :: A ( vm. ctx . new_str ( source) ) )
276
275
}
277
276
Either :: B ( code) => Ok ( Either :: B ( code) ) ,
278
277
} ?;
You can’t perform that action at this time.
0 commit comments