fix(cli): capture signal kills + guard empty env paths (#128 followups)#130
fix(cli): capture signal kills + guard empty env paths (#128 followups)#130
Conversation
…wups) CodeRabbit flagged two remaining minor issues on the Windows diagnostics PR #128 that landed before they were addressed: 1. src/cli.ts:161 — the exit handler only treated non-zero numeric codes as abnormal. Signal-killed processes have code === null and signal !== null (e.g., SIGSEGV, SIGABRT, SIGKILL). Those crashes were silently dropped from startupFailure so the user got the generic "did not become ready" timeout instead of a real diagnosis. On Windows this rarely fires (abnormal exits usually carry codes) but on Unix a segfault in iii-engine would be invisible. Fix: widen the guard to `(code !== null && code !== 0) || (code === null && signal !== null)` so signal-only exits are captured too. Also generate a clearer fallback message when stderr is empty: "process killed by signal SIGSEGV" rather than the old "process exited with code null (SIGSEGV)". 2. src/cli.ts:114 — when USERPROFILE (Windows) or HOME (Unix) is unset, `join("", ".local", "bin", "iii.exe")` produces a relative path like `.local/bin/iii.exe`. Harmless today (the path is checked via existsSync which fails silently), but theoretically it could match an unintended file in the user's current working directory. Fix: guard the env var first, return an empty list (Windows) or skip the per-user path (Unix) when the env var is missing. Keep the absolute /usr/local/bin/iii fallback on Unix since it's valid regardless of HOME. No test changes — whichBinary and fallbackIiiPaths are CLI side-effect paths not covered by unit tests. Tests: 684/684. Build clean.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughUpdated path fallback logic in Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Follow-up to #128. CodeRabbit flagged two remaining minor issues on the Windows diagnostics PR that landed before they were addressed. Both real, both minor, both cheap.
1. Signal-only exits weren't captured
Location: `src/cli.ts` exit handler inside `spawnEngineBackground`
When a child process is killed by a signal (SIGSEGV, SIGABRT, SIGKILL, SIGTERM) Node reports `code === null` and `signal !== null`. The previous guard was:
```ts
if (code !== 0 && code !== null) { ... }
```
which explicitly excluded signal-only exits. A segfault in iii-engine would be silently dropped from `startupFailure`, so the user got the generic "did not become ready within 15s" timeout instead of a real crash diagnosis. On Windows this rarely fires (abnormal exits usually carry numeric codes), but on Linux/macOS a segfaulting iii-engine would be invisible to the CLI.
Fix:
```ts
const abnormal =
(code !== null && code !== 0) || (code === null && signal !== null);
if (abnormal) { ... }
```
Also improved the fallback message when stderr is empty so it reads "process killed by signal SIGSEGV" rather than the old "process exited with code null (SIGSEGV)".
2. Empty `USERPROFILE`/`HOME` produced relative paths
Location: `src/cli.ts` `fallbackIiiPaths()`
Previously:
```ts
const userProfile = process.env["USERPROFILE"] || "";
return [
join(userProfile, ".local", "bin", "iii.exe"),
join(userProfile, "bin", "iii.exe"),
].filter(Boolean);
```
When `USERPROFILE` is unset, `join("", ".local", "bin", "iii.exe")` produces `.local/bin/iii.exe` — a relative path. Harmless today (the path is then fed to `existsSync` which fails silently), but theoretically it could match a file in the user's current working directory and then trigger an unintended `spawn()`.
Fix: guard the env var up front, return an empty list (Windows) or skip the per-user path (Unix) when unset. Keep the absolute `/usr/local/bin/iii` fallback on Unix since it's valid regardless of `HOME`.
Test plan
Related
Summary by CodeRabbit
Bug Fixes
Improvements