File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -254,9 +254,16 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
254254 ) ;
255255 set_exit_code ( 1 ) ;
256256 } else {
257- let reader = File :: open ( path) . map_err_context ( || file. maybe_quote ( ) . to_string ( ) ) ?;
258- let mut buffer = BufReader :: new ( reader) ;
259- nl ( & mut buffer, & mut stats, & settings) ?;
257+ match File :: open ( path) {
258+ Ok ( reader) => {
259+ let mut buffer = BufReader :: new ( reader) ;
260+ nl ( & mut buffer, & mut stats, & settings) ?;
261+ }
262+ Err ( e) => {
263+ show_error ! ( "{}" , e. map_err_context( || file. maybe_quote( ) . to_string( ) ) ) ;
264+ set_exit_code ( 1 ) ;
265+ }
266+ }
260267 }
261268 }
262269 }
Original file line number Diff line number Diff line change 44// file that was distributed with this source code.
55//
66// spell-checker:ignore binvalid finvalid hinvalid iinvalid linvalid nabcabc nabcabcabc ninvalid vinvalid winvalid dabc näää févr
7+
78use uutests:: { at_and_ucmd, new_ucmd, util:: TestScenario , util_name} ;
89
910#[ test]
@@ -414,6 +415,19 @@ fn test_default_body_numbering_multiple_files_and_stdin() {
414415 . stdout_is ( " 1\t a\n 2\t b\n 3\t c\n " ) ;
415416}
416417
418+ #[ test]
419+ fn test_default_body_numbering_multiple_files_with_non_existing_file ( ) {
420+ let ( at, mut ucmd) = at_and_ucmd ! ( ) ;
421+
422+ at. write ( "a.txt" , "a" ) ;
423+ at. write ( "b.txt" , "b" ) ;
424+
425+ ucmd. args ( & [ "a.txt" , "non_existing" , "b.txt" ] )
426+ . fails_with_code ( 1 )
427+ . stdout_is ( " 1\t a\n 2\t b\n " )
428+ . stderr_is ( "nl: non_existing: No such file or directory\n " ) ;
429+ }
430+
417431#[ test]
418432fn test_body_numbering_all_lines_without_delimiter ( ) {
419433 for arg in [ "-ba" , "--body-numbering=a" ] {
You can’t perform that action at this time.
0 commit comments