diff --git a/src/uu/head/src/head.rs b/src/uu/head/src/head.rs index eb863d81492..c86cec9bfd4 100644 --- a/src/uu/head/src/head.rs +++ b/src/uu/head/src/head.rs @@ -7,11 +7,12 @@ use clap::{crate_version, Arg, ArgAction, ArgMatches, Command}; use std::ffi::OsString; +use std::io::ErrorKind::StorageFull; use std::io::{self, ErrorKind, Read, Seek, SeekFrom, Write}; use std::num::TryFromIntError; use thiserror::Error; use uucore::display::Quotable; -use uucore::error::{FromIo, UError, UResult}; +use uucore::error::{strip_errno, FromIo, UError, UResult}; use uucore::line_ending::LineEnding; use uucore::lines::lines; use uucore::{format_usage, help_about, help_usage, show}; @@ -56,6 +57,9 @@ enum HeadError { #[error("{0}")] MatchOption(String), + + #[error("error writing 'standard output': {}", strip_errno(.err))] + WriteError { err: io::Error }, } impl UError for HeadError { @@ -543,11 +547,16 @@ fn uu_head(options: &HeadOptions) -> UResult<()> { } else { file }; - return Err(HeadError::Io { - name: name.to_string(), - err: e, + match e.kind() { + StorageFull => return Err(HeadError::WriteError { err: e }.into()), + _ => { + return Err(HeadError::Io { + name: name.to_string(), + err: e, + } + .into()) + } } - .into()); } first = false; } diff --git a/tests/by-util/test_head.rs b/tests/by-util/test_head.rs index d60b8bb4244..cc6977b639f 100644 --- a/tests/by-util/test_head.rs +++ b/tests/by-util/test_head.rs @@ -533,7 +533,7 @@ fn test_write_to_dev_full() { .pipe_in_fixture(INPUT) .set_stdout(dev_full) .run() - .stderr_contains("No space left on device"); + .stderr_contains("error writing 'standard output': No space left on device"); } } }