Diagnostics: a failed log or report write is silently ignored, so a run can end with nothing to attach #2277

Open
opened 2026-11-26 05:25:21 +00:00 by github-bot · 2 comments
Owner

@⁠itsonewi on GitHub · 2026-11-25 12:03 UTC · original

Summary

The two files every bug report is built on are written best-effort, and a failure says nothing at all.

crates/xcl/src/log.rs (1a0bbe3), init():

if let Some(dir) = p.parent() {
    let _ = std::fs::create_dir_all(dir);
}
if let Ok(f) = File::create(p) {
    if let Ok(mut g) = FILE.lock() {
        *g = Some(f);
    }
}

If create_dir_all or File::create fails, FILE stays None and every xlog_* line afterwards is dropped by write() (if let Some(f) = g.as_mut()). The run continues, launcher.rs has already printed Log: <path> to the console, and that path does not exist.

crates/xcl/src/report.rs, write_final():

if let Ok(s) = serde_json::to_string_pretty(&r) {
    let _ = std::fs::write(boot.report_path(), s);
}

Same shape: the error is dropped, and the exit code is unchanged, so nothing distinguishes "the game failed" from "the diagnostics failed".

Why it matters

.github/ISSUE_TEMPLATE/game.yml opens with "Every run writes a report and a log to %LOCALAPPDATA%\XCL\<title>\logs\ … please attach both", and makes report.json and xcl.log required fields. A user whose %LOCALAPPDATA%\XCL\<title>\ cannot be written - a read-only or roamed profile, a folder left by a different account after a reinstall or a Windows reset, a full disk - gets a normal-looking run, two missing files, and no message to explain either. The natural next step is a bug report that cannot be filled in, or the conclusion that XCL crashed silently.

scripts/smoke.ps1 then fails at Get-Content $log with a path error, not with "XCL could not open its log", which is the one line that would identify the cause.

Suggested fix

One unconditional message per site, naming the path and the OS error:

if let Err(e) = std::fs::create_dir_all(dir) { eprintln!("xcl: cannot create {}: {e}", dir.display()); }
...
Err(e) => eprintln!("xcl: cannot open the log {}: {e}", p.display()),

and the same for boot.report_path(). It has to be eprintln! rather than xlog_error!: write() does echo Error/Warn to stderr independently of FILE, but only when ECHO is on - and ECHO comes from the title's log_to_stderr, which is exactly the setting a user with a broken log path has no reason to have enabled. The game should keep running either way; the point is that the failure is visible once.

Not tested

  • Nothing run: both call sites are read verbatim from 1a0bbe3. The failure needs an unwritable diagnostics folder, which was not reproduced on this machine.

AI use

  • Claude (Opus 5.5) read crates/xcl/src/log.rs, crates/xcl/src/report.rs, crates/xcl/src/host.rs and .github/ISSUE_TEMPLATE/game.yml on 1a0bbe3 and wrote this report; the human account checked each file before opening it.
**@⁠itsonewi** on GitHub · 2026-11-25 12:03 UTC · [original](https://github.com/xcl-dev/xcl/issues/2277) ### Summary The two files every bug report is built on are written best-effort, and a failure says nothing at all. `crates/xcl/src/log.rs` (`1a0bbe3`), `init()`: ```rust if let Some(dir) = p.parent() { let _ = std::fs::create_dir_all(dir); } if let Ok(f) = File::create(p) { if let Ok(mut g) = FILE.lock() { *g = Some(f); } } ``` If `create_dir_all` or `File::create` fails, `FILE` stays `None` and every `xlog_*` line afterwards is dropped by `write()` (`if let Some(f) = g.as_mut()`). The run continues, `launcher.rs` has already printed `Log: <path>` to the console, and that path does not exist. `crates/xcl/src/report.rs`, `write_final()`: ```rust if let Ok(s) = serde_json::to_string_pretty(&r) { let _ = std::fs::write(boot.report_path(), s); } ``` Same shape: the error is dropped, and the exit code is unchanged, so nothing distinguishes "the game failed" from "the diagnostics failed". ### Why it matters `.github/ISSUE_TEMPLATE/game.yml` opens with *"Every run writes a report and a log to `%LOCALAPPDATA%\XCL\<title>\logs\` … please attach both"*, and makes `report.json` and `xcl.log` **required** fields. A user whose `%LOCALAPPDATA%\XCL\<title>\` cannot be written - a read-only or roamed profile, a folder left by a different account after a reinstall or a Windows reset, a full disk - gets a normal-looking run, two missing files, and no message to explain either. The natural next step is a bug report that cannot be filled in, or the conclusion that XCL crashed silently. `scripts/smoke.ps1` then fails at `Get-Content $log` with a path error, not with "XCL could not open its log", which is the one line that would identify the cause. ### Suggested fix One unconditional message per site, naming the path and the OS error: ```rust if let Err(e) = std::fs::create_dir_all(dir) { eprintln!("xcl: cannot create {}: {e}", dir.display()); } ... Err(e) => eprintln!("xcl: cannot open the log {}: {e}", p.display()), ``` and the same for `boot.report_path()`. It has to be `eprintln!` rather than `xlog_error!`: `write()` does echo Error/Warn to stderr independently of `FILE`, but only when `ECHO` is on - and `ECHO` comes from the title's `log_to_stderr`, which is exactly the setting a user with a broken log path has no reason to have enabled. The game should keep running either way; the point is that the failure is visible once. **Not tested** - Nothing run: both call sites are read verbatim from `1a0bbe3`. The failure needs an unwritable diagnostics folder, which was not reproduced on this machine. **AI use** - Claude (Opus 5.5) read `crates/xcl/src/log.rs`, `crates/xcl/src/report.rs`, `crates/xcl/src/host.rs` and `.github/ISSUE_TEMPLATE/game.yml` on `1a0bbe3` and wrote this report; the human account checked each file before opening it.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:25:21 +00:00
Author
Owner

@⁠Creaa on GitHub · 2026-11-25 12:15 UTC · original

Taking this: one eprintln! naming the path and the OS error where log::init cannot create the folder or the file and where report::write_final cannot write report.json; the run keeps going. Unit tests point both at a path under an existing file and check the failure is reported, not dropped.

AI use: Claude Code (Claude Opus 5.5) drafted this.

**@⁠Creaa** on GitHub · 2026-11-25 12:15 UTC · [original](https://github.com/xcl-dev/xcl/issues/2277#issuecomment-7162123004) Taking this: one `eprintln!` naming the path and the OS error where `log::init` cannot create the folder or the file and where `report::write_final` cannot write `report.json`; the run keeps going. Unit tests point both at a path under an existing file and check the failure is reported, not dropped. AI use: Claude Code (Claude Opus 5.5) drafted this.
Author
Owner

@⁠itsonewi on GitHub · 2026-11-25 15:52 UTC · original

This covers what the issue reports: open() names the path and the OS error on stderr, report::save() names the report path, and both have tests. One scope note, not a blocker either way.

The mid-run write path is still silent: log::write() does let _ = f.write_all(line.as_bytes()) (and let _ = f.flush() for warn and above). So a disk that fills, a file the title's antivirus locks, or a log deleted out from under XCL after the first line still loses lines with no message, while the first line of the log was fine and Log: <path> was printed. That is the same class the issue is about, but it is a different call site and a per-line message would be wrong; if you would rather keep this PR to open-time and report-time failures, the issue's title just needs to say so, and the write path is a separate one-line follow-up (write_all failure -> one xlog_error!-free eprintln!, once, like WRITE_FAILED).

Measured on the patch only; I did not build or run it.


AI use: read the patch and the current main of log.rs through the GitHub API; no code was written by an agent here and no build was run.

**@⁠itsonewi** on GitHub · 2026-11-25 15:52 UTC · [original](https://github.com/xcl-dev/xcl/issues/2277#issuecomment-7167389491) This covers what the issue reports: `open()` names the path and the OS error on stderr, `report::save()` names the report path, and both have tests. One scope note, not a blocker either way. The mid-run write path is still silent: `log::write()` does `let _ = f.write_all(line.as_bytes())` (and `let _ = f.flush()` for warn and above). So a disk that fills, a file the title's antivirus locks, or a log deleted out from under XCL after the first line still loses lines with no message, while the first line of the log was fine and `Log: <path>` was printed. That is the same class the issue is about, but it is a different call site and a per-line message would be wrong; if you would rather keep this PR to open-time and report-time failures, the issue's title just needs to say so, and the write path is a separate one-line follow-up (`write_all` failure -> one `xlog_error!`-free `eprintln!`, once, like `WRITE_FAILED`). Measured on the patch only; I did not build or run it. --- **AI use:** read the patch and the current `main` of `log.rs` through the GitHub API; no code was written by an agent here and no build was run.
This discussion has been locked. Commenting is limited to contributors.
No description provided.