diff --git a/src/uu/sort/locales/en-US.ftl b/src/uu/sort/locales/en-US.ftl index ab12a9bbd0..a1980d94a3 100644 --- a/src/uu/sort/locales/en-US.ftl +++ b/src/uu/sort/locales/en-US.ftl @@ -14,6 +14,7 @@ sort-after-help = The key format is FIELD[.CHAR][OPTIONS][,FIELD[.CHAR]][OPTIONS sort-open-failed = open failed: {$path}: {$error} sort-parse-key-error = failed to parse key {$key}: {$msg} sort-cannot-read = cannot read: {$path}: {$error} +sort-read-failed = read failed: {$error} sort-open-tmp-file-failed = failed to open temporary file: {$error} sort-compress-prog-execution-failed = could not run compress program '{$prog}': {$error} sort-compress-prog-terminated-abnormally = {$prog} terminated abnormally diff --git a/src/uu/sort/locales/fr-FR.ftl b/src/uu/sort/locales/fr-FR.ftl index b832da06ac..6605ee5477 100644 --- a/src/uu/sort/locales/fr-FR.ftl +++ b/src/uu/sort/locales/fr-FR.ftl @@ -14,6 +14,7 @@ sort-after-help = Le format de clé est CHAMP[.CAR][OPTIONS][,CHAMP[.CAR]][OPTIO sort-open-failed = échec d'ouverture : {$path} : {$error} sort-parse-key-error = échec d'analyse de la clé {$key} : {$msg} sort-cannot-read = impossible de lire : {$path} : {$error} +sort-read-failed = échec de lecture : {$error} sort-open-tmp-file-failed = échec d'ouverture du fichier temporaire : {$error} sort-compress-prog-execution-failed = impossible d'exécuter le programme de compression '{$prog}' : {$error} sort-compress-prog-terminated-abnormally = {$prog} s'est terminé anormalement diff --git a/src/uu/sort/src/chunks.rs b/src/uu/sort/src/chunks.rs index 4b388dc7bb..df56cf4f3e 100644 --- a/src/uu/sort/src/chunks.rs +++ b/src/uu/sort/src/chunks.rs @@ -17,7 +17,8 @@ use std::{ use memchr::memchr_iter; use self_cell::self_cell; -use uucore::error::{UResult, USimpleError}; +use uucore::error::{UResult, USimpleError, strip_errno}; +use uucore::translate; use crate::{ GeneralBigDecimalParseResult, GlobalSettings, Line, SortMode, numeric_str_cmp::NumInfo, @@ -427,7 +428,12 @@ fn read_to_buffer( Err(e) if e.kind() == ErrorKind::Interrupted => { // retry } - Err(e) => return Err(USimpleError::new(2, e.to_string())), + Err(e) => { + return Err(USimpleError::new( + 2, + translate!("sort-read-failed", "error" => strip_errno(&e)), + )); + } } } } diff --git a/tests/by-util/test_sort.rs b/tests/by-util/test_sort.rs index f12850f28e..9965a9e7f9 100644 --- a/tests/by-util/test_sort.rs +++ b/tests/by-util/test_sort.rs @@ -1182,6 +1182,18 @@ fn test_merge_write_error_does_not_panic() { } } +// A read error must be reported with context and without the raw io::Error suffix. +// It used to print `sort: Input/output error (os error 5)`. +#[test] +#[cfg(target_os = "linux")] +fn test_read_error_message() { + // Reading /proc/self/mem from offset 0 fails with EIO. + new_ucmd!() + .arg("/proc/self/mem") + .fails_with_code(2) + .stderr_only("sort: read failed: Input/output error\n"); +} + #[test] fn test_merge_unique() { new_ucmd!()