fix(update): centralize timeout seconds parsing · openclaw/openclaw@351d056
steipete
·
2026-05-29
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -57,14 +57,15 @@ describe("createGlobalCommandRunner", () => {
|
57 | 57 | try { |
58 | 58 | expect(parseTimeoutMsOrExit("1.5")).toBeNull(); |
59 | 59 | expect(parseTimeoutMsOrExit("10abc")).toBeNull(); |
| 60 | +expect(parseTimeoutMsOrExit("0x10")).toBeNull(); |
60 | 61 | expect(parseTimeoutMsOrExit("0")).toBeNull(); |
61 | 62 | expect(parseTimeoutMsOrExit("-1")).toBeNull(); |
62 | 63 | expect(parseTimeoutMsOrExit(" ")).toBeNull(); |
63 | 64 | expect(parseTimeoutMsOrExit(String(Number.MAX_SAFE_INTEGER))).toBeNull(); |
64 | 65 | |
65 | | -expect(error).toHaveBeenCalledTimes(6); |
| 66 | +expect(error).toHaveBeenCalledTimes(7); |
66 | 67 | expect(error).toHaveBeenCalledWith("--timeout must be a positive integer (seconds)"); |
67 | | -expect(exit).toHaveBeenCalledTimes(6); |
| 68 | +expect(exit).toHaveBeenCalledTimes(7); |
68 | 69 | expect(exit).toHaveBeenCalledWith(1); |
69 | 70 | } finally { |
70 | 71 | error.mockRestore(); |
@@ -78,6 +79,7 @@ describe("createGlobalCommandRunner", () => {
|
78 | 79 | |
79 | 80 | try { |
80 | 81 | expect(parseTimeoutMsOrExit(" 10 ")).toBe(10_000); |
| 82 | +expect(parseTimeoutMsOrExit("+10")).toBe(10_000); |
81 | 83 | expect(parseTimeoutMsOrExit("001")).toBe(1_000); |
82 | 84 | expect(parseTimeoutMsOrExit()).toBeUndefined(); |
83 | 85 | expect(error).not.toHaveBeenCalled(); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -6,6 +6,7 @@ import { resolveRequiredHomeDir } from "../../infra/home-dir.js";
|
6 | 6 | import { resolveOpenClawPackageRoot } from "../../infra/openclaw-root.js"; |
7 | 7 | import { readPackageName, readPackageVersion } from "../../infra/package-json.js"; |
8 | 8 | import { normalizePackageTagInput } from "../../infra/package-tag.js"; |
| 9 | +import { parseStrictPositiveInteger } from "../../infra/parse-finite-number.js"; |
9 | 10 | import { trimLogTail } from "../../infra/restart-sentinel.js"; |
10 | 11 | import { parseSemver } from "../../infra/runtime-guard.js"; |
11 | 12 | import { fetchNpmTagVersion } from "../../infra/update-check.js"; |
@@ -60,13 +61,8 @@ export function parseTimeoutMsOrExit(timeout?: string): number | undefined | nul
|
60 | 61 | return undefined; |
61 | 62 | } |
62 | 63 | const trimmed = timeout.trim(); |
63 | | -const seconds = Number(trimmed); |
64 | | -if ( |
65 | | -!/^\d+$/u.test(trimmed) || |
66 | | -!Number.isSafeInteger(seconds) || |
67 | | -seconds <= 0 || |
68 | | -seconds > MAX_SAFE_TIMEOUT_SECONDS |
69 | | -) { |
| 64 | +const seconds = parseStrictPositiveInteger(trimmed); |
| 65 | +if (seconds === undefined || seconds > MAX_SAFE_TIMEOUT_SECONDS) { |
70 | 66 | defaultRuntime.error(INVALID_TIMEOUT_ERROR); |
71 | 67 | defaultRuntime.exit(1); |
72 | 68 | return null; |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。