Skip to content

date: report errors while reading date files - #14783

Open
ddy314 wants to merge 8 commits into
uutils:mainfrom
ddy314:fix/date-file-read-errors
Open

ddy314 wants to merge 8 commits into
uutils:mainfrom
ddy314:fix/date-file-read-errors

Conversation

@ddy314

@ddy314 ddy314 commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Propagate file/stdin read failures instead of treating them as EOF. Flush completed output, report the input and read error, and exit unsuccessfully. Invalid date lines still allow processing to continue.

Fixes #12672.

Validation: 164 date tests passed, 7 ignored; 37 date unit tests passed, including a reader failing after valid and invalid lines. Clippy and rustfmt passed.

AI-assisted with Codex.

Copilot AI lite review requested due to automatic review settings September 21, 2026 12:50

Copilot AI left a comment

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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

Review effort: Lite
Findings: 1 Medium severity · 1 Low severity

Open (2)
What changed in this PR

Propagates input read failures in date (file/stdin) instead of treating them as EOF, while continuing past invalid date lines; adds user-facing error reporting and tests to validate behavior.

Changes:

  • Introduce DateInputError to distinguish invalid date lines from I/O read failures.
  • Make the date reader iterator surface read errors and stop iteration after the first read failure.
  • Add unit/integration tests and a new localized error string for read-failure reporting.
File Description
tests/​by-util/​test_date.rs Adds a Linux integration test asserting a read error is reported for a problematic input file.
src/​uu/​date/​src/​date.rs Adds DateInputError, propagates read errors distinctly, and adds a unit test for reader failure after valid/invalid lines.
src/​uu/​date/​locales/​en-US.ftl Adds localized message template for read errors.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/by-util/test_date.rs Outdated
Comment thread src/uu/date/src/date.rs Outdated
@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/date/resolution (passes in this run but fails in the 'main' branch)

when using an option to specify date(s), any non-option
argument must be a format string beginning with '+'

date-error-read = {$path}: read error: {$error}

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.

did you check the exact GNU wording/exit code with LANG=C?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes. With LANG=C, GNU coreutils 9.12 exits 1, writes no stdout, and reports gnudate: /proc/self/mem: read error: Input/output error on this glibc host. The uutils result matches after normalizing the executable name. The test keeps the OS error suffix flexible because musl spells it I/O error.

Comment thread src/uu/date/src/date.rs Outdated
});
}
Err(DateInputError::Read(error)) => {
stdout.flush().map_err(DateError::Write)?;

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 above we do let _ = stdout.flush(), could we be consistent?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Made this consistent with the invalid-date arm by using let _ = stdout.flush() in f4a7f1d.

Comment thread src/uu/date/src/date.rs Outdated
}
Err(DateInputError::Read(error)) => {
stdout.flush().map_err(DateError::Write)?;
let path = match &settings.date_source {

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.

could you please carry the path in DateInputError::Read? re-deriving it from date_source with a hardcoded "-" fallback is fragile

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

DateInputError::Read now carries the input path, including the explicit stdin name, in f4a7f1d.

Comment thread src/uu/date/src/date.rs Outdated
DateSource::File(path) => path.as_os_str().maybe_quote().to_string(),
_ => "-".to_string(),
};
return Err(uucore::error::USimpleError::new(

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 Read variant to DateError instead of USimpleError here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added DateError::Read and removed the USimpleError construction in f4a7f1d.

Comment thread src/uu/date/src/date.rs Outdated
Box::new(lines.map_while(Result::ok).map(move |mut bytes| {
) -> Box<dyn Iterator<Item = Result<ParsedDateTime, DateInputError>> + '_> {
let mut lines = BufReader::new(reader).split(b'\n');
let mut failed = false;

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.

the manual failed flag + from_fn is a bit heavy, can't we just fuse after the error?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Replaced the manual flag and from_fn with a mapped iterator plus scan that yields the first read error and then stops in f4a7f1d.

Copilot AI review requested due to automatic review settings September 22, 2026 06:19

Copilot AI left a comment

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.

Copilot review overview

🟡 Changes recommended

parse_dates_from_reader currently uses matches!(result, ...) in a way that moves result, which makes the iterator scan closure not compile as written.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity · 1 Low severity

Open (2)
Resolved since last review (2)

Comment thread src/uu/date/src/date.rs
Comment thread src/uu/date/src/date.rs
Copilot AI review requested due to automatic review settings September 22, 2026 06:58

Copilot AI left a comment

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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

Review effort: Lite
Findings: 1 High severity · 2 Medium severity · 1 Low severity

Open (4)

when using an option to specify date(s), any non-option
argument must be a format string beginning with '+'

date-error-read = {$path}: read error: {$error}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added the read-error key to fr-FR.ftl in ee0e92c. Both date locale bundles now define it.

Comment thread tests/by-util/test_date.rs Outdated
Comment on lines +3453 to +3458
new_ucmd!()
.env("LC_ALL", "C")
.args(&["-f", "/proc/self/mem"])
.fails_with_code(1)
.no_stdout()
.stderr_contains("/proc/self/mem: read error:");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed the procfs-dependent integration case in ee0e92c. The existing unit test uses a reader that fails after complete lines, checks the source path and error, and verifies iteration stops after that error. The date unit and integration suites pass.

Copilot AI review requested due to automatic review settings September 23, 2026 05:35

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@codspeed

codspeed Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 28.01%

⚠️ 1 benchmark spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

⚠️ 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

❌ 1 regressed benchmark
✅ 11 untouched benchmarks
⏩ 460 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Simulation complex_relative_date 277.7 µs 385.7 µs -28.01%

Tip

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


Comparing ddy314:fix/date-file-read-errors (24543cf) with main (ae34722)

Open in CodSpeed

Footnotes

  1. 460 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. ↩

@ddy314

ddy314 commented Sep 26, 2026

Copy link
Copy Markdown
Contributor Author

I checked the benchmark failures. The uu_nl job failed while installing the CodSpeed runner: the download returned a GitHub HTTP 500 page, before any benchmark ran. Could that job be rerun? The performance alert concerns factor, which this date-only PR does not change, and the report flags different runtime environments. A comparison on matching code baselines and runner environments would help verify it.

Copilot AI lite review requested due to automatic review settings October 2, 2026 11:13
@ddy314

ddy314 commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

Updated the branch to resolve the conflict with main. The reader now retains the upstream NUL-byte truncation while reporting I/O errors. The 37 date unit tests and 164 integration tests pass (7 ignored).

Copilot AI left a comment

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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

Review effort: Lite
Findings: 1 High severity · 2 Medium severity · 1 Low severity

Open (4)

Comment thread src/uu/date/src/date.rs Outdated
File::open(path).map_err_context(|| path.as_os_str().maybe_quote().to_string())?;
parse_dates_from_reader(
file,
path.as_os_str().maybe_quote().to_string(),

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.

could you compute the quoted path once and reuse it for the open error too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Computed the quoted path once and reused it for both the open-error context and the reader in 23f3ae7. Updated against current main in 194d28d; all 43 date unit tests and 189 integration tests pass.

Copilot AI lite review requested due to automatic review settings October 16, 2026 13:50

Copilot AI left a comment

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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

4 open findings

🧠 Review effort: Lite

Copilot AI lite review requested due to automatic review settings October 20, 2026 09:27
@ddy314

ddy314 commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

Updated in 24543cf. Merged main and resolved the conflict caused by the escape_for_error rename, preserving the upstream escaping behavior and this PR’s read-error reporting.

Local validation: 43 date unit tests and 192 integration tests passed; formatting passed.

Copilot AI left a comment

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 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.

bug(date): -f with /proc/self/mem errors are ignored

3 participants