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