Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/uucore/src/lib/features/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ use crate::extendedbigdecimal::ExtendedBigDecimal;
pub use argument::{FormatArgument, FormatArguments};

use self::{escape::parse_escape_code, num_format::Formatter};
use crate::{NonUtf8OsStrError, error::UError};
use crate::{
NonUtf8OsStrError,
error::{UError, strip_errno},
};
pub use spec::Spec;
use std::{
error::Error,
Expand Down Expand Up @@ -113,7 +116,7 @@ impl Display for FormatError {
Self::InvalidPrecision(precision) => write!(f, "invalid precision: '{precision}'"),
// TODO: Error message below needs some work
Self::WrongSpecType => write!(f, "wrong % directive type was given"),
Self::IoError(e) => write!(f, "write error: {e}"),
Self::IoError(e) => write!(f, "write error: {}", strip_errno(e)),
Self::NoMoreArguments => write!(f, "no more arguments"),
Self::InvalidArgument(_) => write!(f, "invalid argument"),
Self::MissingHex => write!(f, "missing hexadecimal number in escape"),
Expand Down
12 changes: 12 additions & 0 deletions tests/by-util/test_printf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,18 @@ fn test_emoji_formatting() {
.stdout_only("Status: Success 🚀 🎯 Count: 42\n");
}

#[cfg(target_os = "linux")]
#[test]
fn test_write_error_omits_errno() {
let dev_full = std::fs::File::create("/dev/full").expect("failed to open /dev/full");

new_ucmd!()
.arg("\n")
.set_stdout(dev_full)
.fails_with_code(1)
.stderr_only("printf: write error: No space left on device\n");
}

#[test]
fn test_large_width_format() {
// Test that extremely large width specifications fail gracefully with an error
Expand Down
Loading