Repository navigation
D3D12-GAME-ACTIONS-AND-WATCH-NO-STDERR-PANIC: never panic on closed stderr in game_actions and watch - #2945
Conversation
…NS-AND-WATCH-NO-STDERR-PANIC)
|
Independent closed-stderr check for the launcher helpers on Restoring the old MEASURED with synthetic inputs, OpenAI Codex and a separate read-only review. |
KelboLive
left a comment
There was a problem hiding this comment.
Reviewed at 8dc3855. log_to writing the file sink before the fallible stderr write is the right order, and restoring eprintln! makes the child test exit 101, so the guard is real. The FFI path is safe too: log sits outside catch_unwind, but no longer panics, so the extern "win64" callback cannot unwind across the boundary. No diagnostic regression — game actions still reach log.txt (the deferred failure now gains a file entry too), and watch output is identical on a valid stderr.
Tests are 11/11 under diagnostics and 43/43 default, switches.md check passes, and the merge is clean against current main.
On the duplication with #2946/#2947: three PRs hand-rolling let _ = writeln!(stderr, ...) across four files is tolerable for one-line call sites, and a shared helper would add a leonida_core API for little gain — worth revisiting only if more detached diagnostic paths adopt it. Note the other detached paths still on eprintln! (player.rs, player_find.rs, native_scan.rs, agility.rs), which is outside this PR's claim but the natural next follow-up.
|
Updated in fast-forward commit Verified locally:
AI-assisted. |
VERIFY-2945 — Linux, Fedora 45, Rust 1.98.1, cross-compiled for x86_64-pc-windows-gnu, Wine 11.21, no GPU device, no game filesVerdict: PASS. The pull request removes the last Head 1. What it changes
This is a root-cause fix (remove the panicking primitive from these paths), not a workaround; the helper extraction keeps it simple and modular, and the logging keeps its file sink as the durable record. 2. The new test checks the property that mattersThe property is "a closed stderr pipe must not abort the process, and the file sink still gets the line." Both new tests are self-spawning: the parent spawns the test binary as a child with Because the child asserts that writing to stderr fails, a pass proves the closed-pipe condition really held at runtime — if the write had succeeded, that For the "never panic" claim I also reproduced the root cause on the old expression. I built a scratch Windows binary (run under Wine, because on Linux Rust's std reopens a closed fd 2 to The old 3. What the tests do here
Against the repository's rule "a new test that fails on 4. Any failure I saw, and why it is not this pull requestNone. No test failed on either side, so there is nothing to attribute. The only build failure was the expected red-side compile error (the tests reference 5. What I did not check
|
Summary
Claimed in the coordination issue as:
D3D12-GAME-ACTIONS-AND-WATCH-NO-STDERR-PANIC(#2570 (comment)), following@KelboLive's review note on #2840.Replaces panicking
eprintln!calls on background/hook paths inapps/leonidawith falliblelet _ = writeln!(std::io::stderr(), ...):d3d12/apps/leonida/src/game_actions.rs:log/log_to: writes%TEMP%\leonida-actions\log.txtfirst and writes to stderr withlet _ = writeln!(std::io::stderr(), ...)so a closed stderr pipe at shutdown never panics the title frame hook orleonida-game-actionsthread and never loses thelog.txtentry.deferred(unsafe extern "win64" fn): replaces theeprintln!in thecatch_unwinderror handler (which sat outsidecatch_unwindon anextern "win64"callback, where a stderr panic would abort across FFI) withlog(...), keeping it panic-free and also recording the failure inlog.txt.d3d12/apps/leonida/src/run.rs:report_watch(under#[cfg(all(windows, feature = "diagnostics"))], placed belowwatchsotools/d3d12_switches.pykeepsLEONIDA_WATCH's existing doc summary verbatim) usinglet _ = writeln!(std::io::stderr(), ...)so the detachedLEONIDA_WATCHpolling thread does not panic if stderr is closed.Tests & Verification
eprintln!restored inlog_toandreport_watch, both new subprocess closed-stderr tests fail (RED_EXIT=101, child panics on closed stderr pipe):game_actions::tests::log_writes_file_and_does_not_panic_when_stderr_pipe_is_closedrun::tests::watch_report_does_not_panic_when_stderr_pipe_is_closedcargo test --locked -p leonida --bin leonida --features diagnostics -- run::tests game_actions::tests: 11 passed, 0 failed.cargo test --locked -p leonida --bin leonida: 43 passed, 0 failed.python -I tools/d3d12_switches.py --check d3d12/docs/switches.md: exit 0.python -I scripts/check_no_game_data.py d3d12/apps/leonida/src/game_actions.rs d3d12/apps/leonida/src/run.rs: exit 0.AI Assistance
AI-assisted using Gemini 4 Neon, including a separate read-only independent review pass (which caught a
d3d12_switches.pydoc-comment shadowing risk inrun.rsbefore opening the PR).