Skip to content

fix(system): handle ENOENT in checkCommand and throw on unmatched version in getVersion#337

Open
luch91 wants to merge 1 commit into
genlayerlabs:v0.39from
luch91:v0.39
Open

fix(system): handle ENOENT in checkCommand and throw on unmatched version in getVersion#337
luch91 wants to merge 1 commit into
genlayerlabs:v0.39from
luch91:v0.39

Conversation

@luch91
Copy link
Copy Markdown

@luch91 luch91 commented May 28, 2026

Fixes #301 and #303.

Bug #301 — checkCommand false positive
When a required binary is not installed, child_process.exec
rejects with error.code === 'ENOENT' and empty stderr. The
previous guard if (error.stderr) evaluated to false,
swallowing the error and reporting the tool as present.

Fixed by adding error.code === 'ENOENT' to the condition.

Bug #303 — getVersion silent empty string
When the version regex didn't match (e.g. stdout was
"Docker version 25" with no X.Y.Z pattern), the function
fell through the dead inner try/catch and returned "".
The caller then ran semver.satisfies("", ">=X.Y.Z") → false,
producing a misleading "please update" error when the tool
was already the correct version.

Fixed by removing the dead try/catch and throwing explicitly
when the regex produces no match. The unreachable return ""
is also removed.

Tests

  • Updated existing test that encoded the buggy "" return
    as correct behavior
  • Added ENOENT test case for checkCommand
  • Added non-matching stdout test case for getVersion

506 tests passing, 0 failures.

Summary by CodeRabbit

  • Bug Fixes

    • Improved detection and error handling for missing system tools
    • Enhanced error messages when tool version information cannot be retrieved or parsed
  • Tests

    • Expanded test coverage for error scenarios involving missing tools and invalid version formats

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8dceb3f1-5707-40c5-8d40-600cc2dc48d9

📥 Commits

Reviewing files that changed from the base of the PR and between 82b7958 and 44b3808.

📒 Files selected for processing (2)
  • src/lib/clients/system.ts
  • tests/libs/system.test.ts

📝 Walkthrough

Walkthrough

Two system utility functions gain stricter error handling: checkCommand now detects missing executables via ENOENT errors in addition to stderr, and getVersion validates stdout format using a X.Y.Z regex and throws detailed parse errors instead of returning empty strings. Tests expand to cover these new failure paths.

Changes

System utilities error handling

Layer / File(s) Summary
checkCommand missing binary detection
src/lib/clients/system.ts, tests/libs/system.test.ts
checkCommand expands its missing-requirement guard to catch both ENOENT filesystem errors (executable not found) and stderr output. Test verifies ENOENT is properly rejected as MissingRequirementError.
getVersion error handling and validation
src/lib/clients/system.ts, tests/libs/system.test.ts
getVersion restructures to capture command output, validate stdout, parse version via X.Y.Z regex, and throw on parse failure. Tests expanded with two failure cases: stdout present but non-matching format, and major-only version output.

🎯 2 (Simple) | ⏱️ ~10 minutes

🐰 System checks grow wise and keen,
No more false passes in between,
ENOENT caught, versions parsed true,
Errors now speak—goodbye to "I haven't a clue!" 🔧✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the two main fixes: handling ENOENT in checkCommand and throwing on unmatched version in getVersion, matching the changeset.
Linked Issues check ✅ Passed The PR successfully addresses both requirements from issue #301: checkCommand now treats ENOENT errors as MissingRequirementError, and getVersion now throws instead of returning empty string on version mismatch.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the two bugs identified in issue #301 and updating corresponding tests; no unrelated modifications are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

Actionable comments posted: 0

@luch91
Copy link
Copy Markdown
Author

luch91 commented May 28, 2026

On issue #301 (#301):

Fixed in #337 — added error.code === 'ENOENT' to the
checkCommand catch condition so missing binaries are
correctly reported as absent rather than silently swallowed.

On issue #303 (#303):

Fixed in #337 — removed the dead inner try/catch and added
an explicit throw when the version regex produces no match.
The unreachable return "" is also removed. Updated the
existing test that encoded the buggy behavior and added a
new test for the non-matching stdout case.

@luch91
Copy link
Copy Markdown
Author

luch91 commented May 28, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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] check Command silently succeeds when required tool is missing false positive in dependency check

1 participant