Skip to content

Commit

Permalink
Merge pull request #297 from mingnus/2024-02-23-thin-dump-fixes
Browse files Browse the repository at this point in the history
Fix thin_dump error messages with human_readable format
  • Loading branch information
jthornber authored Feb 23, 2024
2 parents 5f2326c + b3e05f2 commit b2d57da
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
7 changes: 5 additions & 2 deletions src/commands/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,11 @@ pub fn to_exit_code<T>(report: &Report, result: anyhow::Result<T>) -> exitcode::
let root_cause = e.root_cause();
let is_broken_pipe = root_cause
.downcast_ref::<Arc<std::io::Error>>() // quick_xml::Error::Io wraps io::Error in Arc
.map(|err| err.kind() == std::io::ErrorKind::BrokenPipe)
.unwrap_or(false);
.map_or_else(
|| root_cause.downcast_ref::<std::io::Error>(),
|err| Some(err.as_ref()),
)
.map_or(false, |err| err.kind() == std::io::ErrorKind::BrokenPipe);

if !is_broken_pipe {
if e.chain().len() > 1 {
Expand Down
34 changes: 27 additions & 7 deletions tests/thin_dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ fn no_stderr_on_success() -> Result<()> {
//------------------------------------------
// test no stderr on broken pipe errors

#[test]
fn no_stderr_on_broken_pipe() -> Result<()> {
fn test_no_stderr_on_broken_pipe(extra_args: &[&std::ffi::OsStr]) -> Result<()> {
use anyhow::ensure;

let mut td = TestDir::new()?;
Expand All @@ -157,7 +156,9 @@ fn no_stderr_on_broken_pipe() -> Result<()> {
ensure!(libc::pipe2(pipefd.as_mut_slice().as_mut_ptr(), libc::O_CLOEXEC) == 0);
}

let cmd = thin_dump_cmd(args![&md])
let mut args = args![&md].to_vec();
args.extend_from_slice(extra_args);
let cmd = thin_dump_cmd(args)
.to_expr()
.stdout_file(pipefd[1])
.stderr_capture();
Expand All @@ -179,7 +180,16 @@ fn no_stderr_on_broken_pipe() -> Result<()> {
}

#[test]
fn no_stderr_on_broken_fifo() -> Result<()> {
fn no_stderr_on_broken_pipe_xml() -> Result<()> {
test_no_stderr_on_broken_pipe(&[])
}

#[test]
fn no_stderr_on_broken_pipe_humanreadable() -> Result<()> {
test_no_stderr_on_broken_pipe(&args!["--format", "human_readable"])
}

fn test_no_stderr_on_broken_fifo(extra_args: &[&std::ffi::OsStr]) -> Result<()> {
use anyhow::ensure;

let mut td = TestDir::new()?;
Expand All @@ -194,9 +204,9 @@ fn no_stderr_on_broken_fifo() -> Result<()> {
ensure!(libc::mkfifo(c_str.as_ptr(), 0o666) == 0);
};

let cmd = thin_dump_cmd(args![&md, "-o", &out_fifo])
.to_expr()
.stderr_capture();
let mut args = args![&md, "-o", &out_fifo].to_vec();
args.extend_from_slice(extra_args);
let cmd = thin_dump_cmd(args).to_expr().stderr_capture();
let handle = cmd.unchecked().start()?;

let fifo = std::fs::File::open(out_fifo)?;
Expand All @@ -209,6 +219,16 @@ fn no_stderr_on_broken_fifo() -> Result<()> {
Ok(())
}

#[test]
fn no_stderr_on_broken_fifo_xml() -> Result<()> {
test_no_stderr_on_broken_fifo(&[])
}

#[test]
fn no_stderr_on_broken_fifo_humanreadable() -> Result<()> {
test_no_stderr_on_broken_fifo(&args!["--format", "human_readable"])
}

//------------------------------------------
// test dump metadata snapshot from a live metadata
// here we use a corrupted metadata to ensure that "thin_dump -m" reads the
Expand Down

0 comments on commit b2d57da

Please sign in to comment.