diff --git a/scripts/openclaw-cross-os-release-checks.ts b/scripts/openclaw-cross-os-release-checks.ts index 909d9642b416..c40ab4a8a365 100644 --- a/scripts/openclaw-cross-os-release-checks.ts +++ b/scripts/openclaw-cross-os-release-checks.ts @@ -3011,25 +3011,29 @@ export function appendLatestNpmDebugLogTail( env = process.env, platform = process.platform, ) { - const candidates = resolveNpmDebugLogDirs(homeDir, env, platform) - .flatMap(findNpmDebugLogs) - .toSorted((left, right) => left.mtimeMs - right.mtimeMs); - const latest = candidates.at(-1); - if (!latest) { + try { + const candidates = resolveNpmDebugLogDirs(homeDir, env, platform) + .flatMap(findNpmDebugLogs) + .toSorted((left, right) => left.mtimeMs - right.mtimeMs); + const latest = candidates.at(-1); + if (!latest) { + return ""; + } + + const tail = readLogTextWindow(latest.path, { maxBytes: CROSS_OS_NPM_DEBUG_LOG_TAIL_BYTES }); + if (!tail.trim()) { + return ""; + } + + appendFileSync( + logPath, + `\n${new Date().toISOString()} npm-debug-log path=${latest.path}\n${tail}\n`, + "utf8", + ); + return tail; + } catch { return ""; } - - const tail = readLogTextWindow(latest.path, { maxBytes: CROSS_OS_NPM_DEBUG_LOG_TAIL_BYTES }); - if (!tail.trim()) { - return ""; - } - - appendFileSync( - logPath, - `\n${new Date().toISOString()} npm-debug-log path=${latest.path}\n${tail}\n`, - "utf8", - ); - return tail; } export function resolveNpmDebugLogDirs(homeDir, env = process.env, platform = process.platform) { diff --git a/test/scripts/openclaw-cross-os-release-checks.test.ts b/test/scripts/openclaw-cross-os-release-checks.test.ts index 35876fb64433..747b6b7f2fa5 100644 --- a/test/scripts/openclaw-cross-os-release-checks.test.ts +++ b/test/scripts/openclaw-cross-os-release-checks.test.ts @@ -1417,6 +1417,24 @@ describe("scripts/openclaw-cross-os-release-checks", () => { } }); + it("keeps npm debug log collection best-effort", () => { + const dir = mkdtempSync(join(tmpdir(), "openclaw-cross-os-npm-debug-best-effort-")); + try { + const homeDir = join(dir, "home"); + const logPath = join(dir, "install.log"); + const logsDir = join(dir, "not-a-directory"); + writeFileSync(logPath, "install failed\n"); + writeFileSync(logsDir, "not a directory\n"); + + expect(appendLatestNpmDebugLogTail(homeDir, logPath, { npm_config_logs_dir: logsDir })).toBe( + "", + ); + expect(readFileSync(logPath, "utf8")).toBe("install failed\n"); + } finally { + rmSync(dir, { recursive: true, force: true }); + } + }); + it("resolves relative npm log config from the install working directory", () => { const dir = mkdtempSync(join(tmpdir(), "openclaw-cross-os-npm-relative-logs-")); try {