@@ -34,24 +34,21 @@ impl Bundle {
3434
3535 for file_path in ftl_filenames. iter ( ) {
3636 let path_string = file_path. to_string ( ) ;
37- let contents = match fs:: read_to_string ( path_string) {
38- Ok ( contents) => contents,
39- Err ( _) => return Err ( PyFileNotFoundError :: new_err ( file_path. to_string ( ) ) ) ,
40- } ;
37+ let contents = fs:: read_to_string ( path_string)
38+ . map_err ( |_| PyFileNotFoundError :: new_err ( file_path. to_string ( ) ) ) ?;
4139
4240 let resource = match FluentResource :: try_new ( contents) {
4341 Ok ( resource) => resource,
42+ Err ( _) if strict => {
43+ return Err ( ParserError :: new_err ( format ! (
44+ "Error when parsing {}." ,
45+ file_path
46+ ) ) )
47+ }
4448 Err ( error) => {
45- if strict {
46- return Err ( ParserError :: new_err ( format ! (
47- "Error when parsing {}." ,
48- file_path
49- ) ) ) ;
50- } else {
51- // The first element of the error is the parsed resource, minus any
52- // invalid messages.
53- error. 0
54- }
49+ // The first element of the error is the parsed resource, minus any
50+ // invalid messages.
51+ error. 0
5552 }
5653 } ;
5754 bundle. add_resource_overriding ( resource) ;
@@ -69,21 +66,15 @@ impl Bundle {
6966 ) -> PyResult < String > {
7067 self . bundle . set_use_isolating ( use_isolating) ;
7168
72- let msg = match self . bundle . get_message ( identifier ) {
73- Some ( m ) => m ,
74- None => return Err ( PyValueError :: new_err ( format ! ( "{} not found" , identifier) ) ) ,
75- } ;
69+ let msg = self
70+ . bundle
71+ . get_message ( identifier)
72+ . ok_or_else ( || ( PyValueError :: new_err ( format ! ( "{identifier} not found" ) ) ) ) ? ;
7673
7774 let mut errors = vec ! [ ] ;
78- let pattern = match msg. value ( ) {
79- Some ( m) => m,
80- None => {
81- return Err ( PyValueError :: new_err ( format ! (
82- "{} - Message has no value." ,
83- identifier
84- ) ) )
85- }
86- } ;
75+ let pattern = msg. value ( ) . ok_or_else ( || {
76+ PyValueError :: new_err ( format ! ( "{identifier} - Message has no value." , ) )
77+ } ) ?;
8778
8879 let mut args = FluentArgs :: new ( ) ;
8980
0 commit comments