Skip to content

Commit f3cded8

Browse files
committed
fix: improve ENOENT messaging, clean up inline require and empty catch
- Special-case ENOENT in validateApiKey to show "curl is not installed" instead of the raw "spawnSync curl ENOENT" message. - Import spawnSync at module top alongside execSync instead of inline require("child_process").spawnSync inside the function. - Add explanatory comment to empty catch block in registry backup to clarify the best-effort intent.
1 parent 5394242 commit f3cded8

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

bin/lib/credentials.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
const fs = require("fs");
55
const path = require("path");
66
const readline = require("readline");
7-
const { execSync } = require("child_process");
7+
const { execSync, spawnSync } = require("child_process");
88

99
const CREDS_DIR = path.join(process.env.HOME || "/tmp", ".nemoclaw");
1010
const CREDS_FILE = path.join(CREDS_DIR, "credentials.json");
@@ -104,7 +104,7 @@ function validateApiKey(key) {
104104
try {
105105
// Pass the auth header via stdin using -H @- so the API key
106106
// does not appear in process arguments visible via ps aux.
107-
const result = require("child_process").spawnSync(
107+
const result = spawnSync(
108108
"curl",
109109
[
110110
"-sf",
@@ -122,6 +122,9 @@ function validateApiKey(key) {
122122
);
123123
// Check for local spawn errors (curl missing, timeout) before inspecting stdout.
124124
if (result.error) {
125+
if (result.error.code === "ENOENT") {
126+
return { ok: false, fatal: false, message: "Could not validate key (curl is not installed). Proceeding with saved key." };
127+
}
125128
const reason = result.error.code === "ETIMEDOUT" ? "timed out" : result.error.message || "unknown error";
126129
return { ok: false, fatal: false, message: `Could not validate key (${reason}). Proceeding with saved key.` };
127130
}

bin/lib/registry.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ function load() {
1818
const backupFile = REGISTRY_FILE + ".corrupt." + Date.now();
1919
try {
2020
fs.copyFileSync(REGISTRY_FILE, backupFile);
21-
} catch {}
21+
} catch {
22+
// Best-effort backup — if the copy fails (e.g., disk full), we still
23+
// warn the user and reset the registry. The corrupt file remains in place.
24+
}
2225
console.error(` [warn] Registry file is corrupted. Backed up to: ${path.basename(backupFile)}`);
2326
console.error(" [warn] Sandbox list has been reset. Run 'nemoclaw onboard' to recreate.");
2427
}

0 commit comments

Comments
 (0)