Skip to content
Closed
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
8 changes: 4 additions & 4 deletions src/uu/cp/src/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use uucore::{backup_control, update_control};
// requires these enum.
pub use uucore::{backup_control::BackupMode, update_control::UpdateMode};
use uucore::{
format_usage, parser::shortcut_value_parser::ShortcutValueParser, prompt_yes, show_error,
format_usage, parser::shortcut_value_parser::ShortcutValueParser, print_error, prompt_yes,
show_warning,
};

Expand Down Expand Up @@ -833,7 +833,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
// code should still be EXIT_ERR as does GNU cp
CpError::NotAllFilesCopied => {}
// Else we caught a fatal bubbled-up error, log it to stderr
_ => show_error!("{error}"),
_ => print_error!("{error}"),
}
set_exit_code(EXIT_ERR);
}
Expand Down Expand Up @@ -1344,10 +1344,10 @@ fn show_error_if_needed(error: &CpError) {
// Format IoErrContext using strip_errno to remove "(os error N)" suffix
// for GNU-compatible output
CpError::IoErrContext(io_err, context) => {
show_error!("{}: {}", context, uucore::error::strip_errno(io_err));
print_error!("{}: {}", context, uucore::error::strip_errno(io_err));
}
_ => {
show_error!("{error}");
print_error!("{error}");
}
}
}
Expand Down
27 changes: 13 additions & 14 deletions src/uucore/src/lib/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,9 @@ macro_rules! show_if_err(
})
);

/// Show an error to stderr in a similar style to GNU coreutils.
///
/// Takes a [`format!`]-like input and prints it to stderr. The output is
/// prepended with the current utility's name.
///
/// # Examples
///
/// ```
/// # #[macro_use]
/// # extern crate uucore;
/// # fn main() {
/// show_error!("Couldn't apply {} to {}", "foo", "bar");
/// # }
/// ```
// todo: Investigate how to show an error to stderr
// show_error! cause abort with 2>/dev/full
// Maybe, we should switch to print_error! macro ?
#[macro_export]
macro_rules! show_error(
($($args:tt)+) => ({
Expand All @@ -156,6 +145,16 @@ macro_rules! show_error(
})
);

#[macro_export]
macro_rules! print_error(
($($args:tt)+) => ({
use std::io::Write as _;
let mut error = std::io::stderr().lock();
let _ = write!(error, "{}: ", $crate::util_name());
let _ = writeln!(error, $($args)+);
})
);

/// Print a warning message to stderr.
///
/// Takes [`format!`]-compatible input and prepends it with the current
Expand Down
Loading