fix(cli): detect tar failure in debug --output and set non-zero exit code#1770
fix(cli): detect tar failure in debug --output and set non-zero exit code#1770kagura-agent wants to merge 1 commit intoNVIDIA:mainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughcreateTarball was exported and updated to capture the tar child process result, detect failures, log a red error, set Changes
Sequence Diagram(s)sequenceDiagram
participant CLI as CLI (runDebug)
participant Debug as createTarball
participant Tar as tar (child)
participant Console as Console
CLI->>Debug: createTarball(collectDir, output)
Debug->>Tar: spawnSync tar -czf output -C collectDir .
Tar-->>Debug: exitCode / signal
alt exitCode == 0
Debug-->>CLI: return true
CLI->>Console: print "Tarball written..." and instructions
else failure (non-zero or signal)
Debug->>Console: error("[debug] Tarball creation failed: ...")
Debug-->>CLI: return false (set process.exitCode = 1)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/lib/debug.ts (1)
435-447: Return a boolean fromcreateTarballso callers can suppress success-style footer text on failure.Right now
createTarballonly mutatesprocess.exitCode;runDebugstill prints completion guidance afterward. Returning an explicit success flag makes the control flow clearer and avoids mixed messaging.Proposed refactor
-export function createTarball(collectDir: string, output: string): void { +export function createTarball(collectDir: string, output: string): boolean { const result = spawnSync("tar", ["czf", output, "-C", dirname(collectDir), basename(collectDir)], { stdio: "inherit", timeout: 60_000, }); if (result.status !== 0 || result.signal) { const reason = result.signal ? `killed by signal ${result.signal}` : `exited with code ${result.status ?? "unknown"}`; error(`Failed to create tarball at ${output} (tar ${reason})`); process.exitCode = 1; - return; + return false; } info(`Tarball written to ${output}`); warn( "Known secrets are auto-redacted, but please review for any remaining sensitive data before sharing.", ); info("Attach this file to your GitHub issue."); + return true; }- if (output) { - createTarball(collectDir, output); - } + const tarOk = output ? createTarball(collectDir, output) : true; console.log(""); - info("Done. If filing a bug, run with --output and attach the tarball to your issue:"); - info(" nemoclaw debug --output /tmp/nemoclaw-debug.tar.gz"); + if (tarOk) { + info("Done. If filing a bug, run with --output and attach the tarball to your issue:"); + info(" nemoclaw debug --output /tmp/nemoclaw-debug.tar.gz"); + } else { + warn("Diagnostics were collected, but tarball creation failed."); + }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/lib/debug.ts` around lines 435 - 447, The createTarball function currently only sets process.exitCode on failure; change its signature to return a boolean (true on success, false on failure), keep the existing spawnSync logic and error logging but return false where you set process.exitCode = 1 (and return true at the end on success). Update callers (e.g., runDebug) to capture the boolean result from createTarball and use it to suppress any post-run success/footer messages when false. Ensure the function name createTarball remains and only the return type/returns plus caller checks are modified.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/lib/debug.ts`:
- Around line 435-447: The createTarball function currently only sets
process.exitCode on failure; change its signature to return a boolean (true on
success, false on failure), keep the existing spawnSync logic and error logging
but return false where you set process.exitCode = 1 (and return true at the end
on success). Update callers (e.g., runDebug) to capture the boolean result from
createTarball and use it to suppress any post-run success/footer messages when
false. Ensure the function name createTarball remains and only the return
type/returns plus caller checks are modified.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 9a26f6c6-98b9-4013-b666-3e6e1918e76d
📒 Files selected for processing (2)
src/lib/debug.test.tssrc/lib/debug.ts
…code (NVIDIA#1765) `nemoclaw debug --output <invalid-path>` would print 'Tarball written to ...' and exit 0 even when tar failed. Now checks spawnSync return status and signal, reports the error, and sets process.exitCode = 1. Changes: - Check spawnSync result.status and result.signal in createTarball - Report error with red-colored message on failure - Set process.exitCode = 1 so the command exits non-zero - Export createTarball for testability - Add regression tests for both success and failure paths Signed-off-by: kagura-agent <kagura.chen28@gmail.com>
cbb0fa2 to
de1911a
Compare
|
@coderabbitai Good suggestion — updated |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 297756 🏁 Script executed: Length of output: 11156 🏁 Script executed: Length of output: 10021
Looks good to me. Optional nit for later: consider mapping signal termination to a distinct exit code (128 + signal) for parity with uninstall-command, but keeping 1 is perfectly fine since you already include the signal detail in the error. |
|
✨ Thanks for submitting this PR, which proposes a fix for a bug where tarball creation failure is not detected and a non-zero exit code is not set. Possibly related open issues: |
Problem
nemoclaw debug --output /nonexistent/path/debug.tar.gzprints "Tarball written to ..." and exits with code 0 even when tar fails. Users see a success message despite no tarball being created.Fixes #1765
Root Cause
createTarball()calledspawnSync("tar", ...)without checking the return status. The success message was unconditionally printed.Fix
spawnSyncresult.statusand.signalprocess.exitCode = 1Testing
createTarball:process.exitCode === 1npx vitest run src/lib/debug.test.ts— 10/10)tscclean,eslintclean,prettiercleanSigned-off-by: kagura-agent kagura.chen28@gmail.com
Summary by CodeRabbit
Bug Fixes
Tests