Skip to content

uucore: translate! UIoError error messages, reduce error message duplication - #13680

Open
RenjiSann wants to merge 5 commits into
uutils:mainfrom
RenjiSann:l10n-uioerror
Open

RenjiSann wants to merge 5 commits into
uutils:mainfrom
RenjiSann:l10n-uioerror

Conversation

@RenjiSann

Copy link
Copy Markdown
Collaborator

This is an attempt to fix #11451

@codspeed

codspeed Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will degrade performance by 8.12%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 8 improved benchmarks
❌ 27 regressed benchmarks
✅ 312 untouched benchmarks
⏩ 46 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Simulation complex_relative_date 314.1 µs 437.6 µs -28.22%
❌ Memory factor_multiple_u64s[2] 54.1 KB 66.2 KB -18.3%
❌ Memory hostname_basic 56.3 KB 68.4 KB -17.71%
❌ Memory seq_custom_separator 58.4 KB 70.5 KB -17.17%
❌ Memory wc_lines_extreme_line_lengths[(100000, 200)] 65 KB 77.1 KB -15.7%
❌ Memory nl_many_lines[100000] 66.2 KB 78.3 KB -15.47%
❌ Memory unexpand_many_lines[100000] 67 KB 79.1 KB -15.32%
❌ Memory expand_custom_tabstops[50000] 67 KB 79.1 KB -15.31%
❌ Memory cut_characters_long_lines 69 KB 81.1 KB -14.93%
❌ Memory fold_custom_width[50000] 76 KB 88.1 KB -13.75%
❌ Memory split_numeric_suffix 80.5 KB 92.6 KB -13.07%
❌ Memory df_deep_directory 80.7 KB 92.8 KB -13.04%
❌ Memory join_custom_separator 86 KB 98.1 KB -12.34%
❌ Memory cksum_multiple_files 91.2 KB 103.3 KB -11.72%
❌ Memory tee_stdin_file[10000000] 69.7 KB 78.7 KB -11.48%
❌ Memory rm_recursive_tree 98 KB 110.1 KB -11%
❌ Simulation hostname_basic 332.7 µs 371.8 µs -10.52%
❌ Memory timer_expiry_latency[0.001] 79.9 KB 88.9 KB -10.17%
❌ Memory cat_default[10000] 81.4 KB 89.9 KB -9.49%
❌ Simulation tee_stdin_file[10000000] 367.9 µs 404.5 µs -9.06%
... ... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing RenjiSann:l10n-uioerror (7782e8b) with main (5ec266b)

Open in CodSpeed

Footnotes

  1. 46 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@RenjiSann

Copy link
Copy Markdown
Collaborator Author

Well, that's some nasty performance regression

@github-actions

github-actions Bot commented Jul 31, 2026 •

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/pr/bounded-memory (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/cut/bounded-memory (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/misc/io-errors (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tail/retry (passes in this run but fails in the 'main' branch)

@RenjiSann

Copy link
Copy Markdown
Collaborator Author

For some reason I don't get, translate!() in uucore in the du binary is broken 🤔

@RenjiSann
RenjiSann force-pushed the l10n-uioerror branch 2 times, most recently from c178883 to ea01d67 Compare August 4, 2026 11:30
error-invalid-argument = Argument invalide
error-is-a-directory = { $file }: Est un répertoire

uio-err-not-found = Aucun fichier ou répertoire de ce type

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just don't put the id then

Comment thread src/uu/du/src/du.rs Outdated
print_tx.send(Err(std::io::Error::new(
std::io::ErrorKind::InvalidData,
print_tx.send(Err(std::io::Error::other(
"Too many levels of symbolic links",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line too i guess :)

Comment thread src/uucore/src/lib/mods/error.rs Outdated
// and we want to strip the "(os error X)" suffix.
match self.inner.kind() {
NotFound => "No such file or directory",
PermissionDenied => "Permission denied",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oups

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I get this one 😅

@RenjiSann
RenjiSann force-pushed the l10n-uioerror branch 3 times, most recently from 7f5e6bf to fdbdd4a Compare August 4, 2026 14:32
@RenjiSann

RenjiSann commented Aug 4, 2026 •

Copy link
Copy Markdown
Collaborator Author

I introduced a new dev dependency two_rusty_fork, which allows to run tests in separate processes.
I think it's better to use that than to complexify locale.rs even further for the sake of tests conflicting with each other.

I'm considering splitting the work into 2 separate PRs, wdyt @sylvestre ?

@RenjiSann
RenjiSann marked this pull request as ready for review August 4, 2026 14:34
@sylvestre

Copy link
Copy Markdown
Contributor

i am fine in this pr, i am more worried about the perf impact :)

@RenjiSann

Copy link
Copy Markdown
Collaborator Author

i am more worried about the perf impact :)

Yep, as do I. not sure how we can avoid it though. Do you happen to know why fluent_bundle can't be passed between threads ?

@@ -193,17 +122,15 @@ thread_local! {
)
)]
static LOCALIZER: OnceLock<Localizer> = const { OnceLock::new() };
/// Built on the first lookup that misses every ordinary bundle; `None`
/// when there are no error strings to be found at all.
// Avoid duplicated and high-cost localizer setup
#[cfg_attr(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we allow missing_const_for_thread_local at crate level now: ab3e572

@xtqqczze

Copy link
Copy Markdown
Collaborator

i am fine in this pr, i am more worried about the perf impact :)

By the way, #15602 will run tests in separate processes. So measurements will be more accurate once that has been merged.

TimedOut => translate!("uio-err-timed-out"),
WriteZero => translate!("uio-err-write-zero"),
Interrupted => translate!("uio-err-interrupted"),
UnexpectedEof => translate!("uio-err-unexpected-eof"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a test showing a translated UIoError (fr-FR) too

}
// These are errors that come directly from the OS.
// We want to normalize their messages across systems,
// and we want to strip the "(os error X)" suffix.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

about my "oups": without the raw_os_error() check, custom messages are lost, e.g. csplit csplit-stream-not-utf8 now prints "Invalid data", mv mv-error-dangling-symlink prints "No such file or directory".
could you please keep the check (the comment above is stale too) and add a test for it?


fn get_message_internal(id: &str, args: Option<FluentArgs>) -> String {
// Disable lazy setup evaluation for tests.
#[cfg(not(test))]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the lazy setup is never tested? please add a test for it (a spawned thread getting translated messages)


/// Called by precaution when trying to get a message, in case we are in
/// a separate thread and the thread_local LOCALIZER is not created yet.
pub fn lazy_thread_setup_localization() -> Result<(), LocalizationError> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it need to be pub?

fn test_create_bundle_success() {
let temp_dir = create_test_locales_dir();
let locale = LanguageIdentifier::from_str("en-US").unwrap();
rusty_fork_test! {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one rusty_fork_test! block can hold all the tests, no? and the thread::spawn inside becomes useless

Comment thread Cargo.lock
checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
dependencies = [
"windows-sys 0.60.2",
"windows-sys 0.61.2",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please drop the windows-sys bumps, unrelated to this pr

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UIoError messages are not translated

3 participants