mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-23 12:18:11 +00:00
24 lines
784 B
JavaScript
24 lines
784 B
JavaScript
// Environment limit helpers for E2E subprocess scenarios.
|
|
export function readPositiveIntEnv(name, fallback, env = process.env) {
|
|
const raw = env[name] ?? fallback;
|
|
const text = raw == null ? "unset" : String(raw).trim();
|
|
if (!/^\d+$/u.test(text)) {
|
|
throw new Error(`invalid ${name}: ${text}`);
|
|
}
|
|
const value = Number(text);
|
|
if (!Number.isSafeInteger(value) || value <= 0) {
|
|
throw new Error(`invalid ${name}: ${text}`);
|
|
}
|
|
return value;
|
|
}
|
|
|
|
export function readTcpPortEnv(name, fallback, env = process.env) {
|
|
const value = readPositiveIntEnv(name, fallback, env);
|
|
if (value > 65_535) {
|
|
const raw = env[name] ?? fallback;
|
|
const text = raw == null ? "unset" : String(raw).trim();
|
|
throw new Error(`invalid ${name}: ${text}`);
|
|
}
|
|
return value;
|
|
}
|