Skip to content
Myr

Handle IO errors based on type, closes #737

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Peter · committed by David Peter · parent d9697d1 · Browse files · 2 files+10 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+10 added−4 removed

  • tests:+1 added−1 removed
  • other:+9 added−3 removed

2 files+10 added−4 removed

modified:src/output.rs+9 added-3 removed
4 unmodified lines
5use std::sync::Arc;67use lscolors::{LsColors, Style};89use crate::error::print_error;10use crate::exit_codes::ExitCode;11use crate::filesystem::strip_current_dir;12use crate::options::Options;13
19 unmodified lines
33 } else {34 print_entry_uncolorized(stdout, path, config)35 };3636 if r.is_err() {37 // Probably a broken pipe. Exit gracefully.38 process::exit(ExitCode::GeneralError.into());37 if let Err(e) = r {38 if e.kind() == ::std::io::ErrorKind::BrokenPipe {39 // Exit gracefully in case of a broken pipe (e.g. 'fd ... | head -n 3').40 process::exit(0);41 } else {42 print_error(format!("Could not write to output: {}", e));43 process::exit(ExitCode::GeneralError.into());44 }45 }46}4748// TODO: this function is performance critical and can probably be optimized
77 unmodified lines
modified:tests/tests.rs+1 added-1 removed
1661 unmodified lines
1662 // Ignore base directory when absolute path is used1663 let (te, abs_path) = get_test_env_with_abs_path(DEFAULT_DIRS, DEFAULT_FILES);1664 let abs_base_dir = &format!("{abs_path}/one/two", abs_path = &abs_path);1665 te.assert_output(1666 &["--base-directory", &abs_base_dir, "foo", &abs_path],1666 &["--base-directory", abs_base_dir, "foo", &abs_path],1667 &format!(1668 "{abs_path}/a.foo1669 {abs_path}/one/b.foo1670 {abs_path}/one/two/c.foo
125 unmodified lines