mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-03 03:03:24 -04:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -90,7 +90,9 @@ describe("attachChildProcessBridge", () => {
|
||||
const afterSigterm = process.listeners("SIGTERM");
|
||||
const addedSigterm = afterSigterm.find((listener) => !beforeSigterm.has(listener));
|
||||
|
||||
if (!child.stdout) throw new Error("expected stdout");
|
||||
if (!child.stdout) {
|
||||
throw new Error("expected stdout");
|
||||
}
|
||||
const portLine = await waitForLine(child.stdout);
|
||||
const port = Number(portLine);
|
||||
expect(Number.isFinite(port)).toBe(true);
|
||||
@@ -98,7 +100,9 @@ describe("attachChildProcessBridge", () => {
|
||||
expect(await canConnect(port)).toBe(true);
|
||||
|
||||
// Simulate systemd sending SIGTERM to the parent process.
|
||||
if (!addedSigterm) throw new Error("expected SIGTERM listener");
|
||||
if (!addedSigterm) {
|
||||
throw new Error("expected SIGTERM listener");
|
||||
}
|
||||
addedSigterm();
|
||||
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
|
||||
@@ -27,7 +27,9 @@ const lanes = new Map<string, LaneState>();
|
||||
|
||||
function getLaneState(lane: string): LaneState {
|
||||
const existing = lanes.get(lane);
|
||||
if (existing) return existing;
|
||||
if (existing) {
|
||||
return existing;
|
||||
}
|
||||
const created: LaneState = {
|
||||
lane,
|
||||
queue: [],
|
||||
@@ -41,7 +43,9 @@ function getLaneState(lane: string): LaneState {
|
||||
|
||||
function drainLane(lane: string) {
|
||||
const state = getLaneState(lane);
|
||||
if (state.draining) return;
|
||||
if (state.draining) {
|
||||
return;
|
||||
}
|
||||
state.draining = true;
|
||||
|
||||
const pump = () => {
|
||||
@@ -130,7 +134,9 @@ export function enqueueCommand<T>(
|
||||
export function getQueueSize(lane: string = CommandLane.Main) {
|
||||
const resolved = lane.trim() || CommandLane.Main;
|
||||
const state = lanes.get(resolved);
|
||||
if (!state) return 0;
|
||||
if (!state) {
|
||||
return 0;
|
||||
}
|
||||
return state.queue.length + state.active;
|
||||
}
|
||||
|
||||
@@ -145,7 +151,9 @@ export function getTotalQueueSize() {
|
||||
export function clearCommandLane(lane: string = CommandLane.Main) {
|
||||
const cleaned = lane.trim() || CommandLane.Main;
|
||||
const state = lanes.get(cleaned);
|
||||
if (!state) return 0;
|
||||
if (!state) {
|
||||
return 0;
|
||||
}
|
||||
const removed = state.queue.length;
|
||||
state.queue.length = 0;
|
||||
return removed;
|
||||
|
||||
@@ -25,8 +25,12 @@ export async function runExec(
|
||||
try {
|
||||
const { stdout, stderr } = await execFileAsync(command, args, options);
|
||||
if (shouldLogVerbose()) {
|
||||
if (stdout.trim()) logDebug(stdout.trim());
|
||||
if (stderr.trim()) logError(stderr.trim());
|
||||
if (stdout.trim()) {
|
||||
logDebug(stdout.trim());
|
||||
}
|
||||
if (stderr.trim()) {
|
||||
logError(stderr.trim());
|
||||
}
|
||||
}
|
||||
return { stdout, stderr };
|
||||
} catch (err) {
|
||||
@@ -65,7 +69,9 @@ export async function runCommandWithTimeout(
|
||||
|
||||
const shouldSuppressNpmFund = (() => {
|
||||
const cmd = path.basename(argv[0] ?? "");
|
||||
if (cmd === "npm" || cmd === "npm.cmd" || cmd === "npm.exe") return true;
|
||||
if (cmd === "npm" || cmd === "npm.cmd" || cmd === "npm.exe") {
|
||||
return true;
|
||||
}
|
||||
if (cmd === "node" || cmd === "node.exe") {
|
||||
const script = argv[1] ?? "";
|
||||
return script.includes("npm-cli.js");
|
||||
@@ -75,8 +81,12 @@ export async function runCommandWithTimeout(
|
||||
|
||||
const resolvedEnv = env ? { ...process.env, ...env } : { ...process.env };
|
||||
if (shouldSuppressNpmFund) {
|
||||
if (resolvedEnv.NPM_CONFIG_FUND == null) resolvedEnv.NPM_CONFIG_FUND = "false";
|
||||
if (resolvedEnv.npm_config_fund == null) resolvedEnv.npm_config_fund = "false";
|
||||
if (resolvedEnv.NPM_CONFIG_FUND == null) {
|
||||
resolvedEnv.NPM_CONFIG_FUND = "false";
|
||||
}
|
||||
if (resolvedEnv.npm_config_fund == null) {
|
||||
resolvedEnv.npm_config_fund = "false";
|
||||
}
|
||||
}
|
||||
|
||||
const stdio = resolveCommandStdio({ hasInput, preferInherit: true });
|
||||
@@ -109,13 +119,17 @@ export async function runCommandWithTimeout(
|
||||
stderr += d.toString();
|
||||
});
|
||||
child.on("error", (err) => {
|
||||
if (settled) return;
|
||||
if (settled) {
|
||||
return;
|
||||
}
|
||||
settled = true;
|
||||
clearTimeout(timer);
|
||||
reject(err);
|
||||
});
|
||||
child.on("close", (code, signal) => {
|
||||
if (settled) return;
|
||||
if (settled) {
|
||||
return;
|
||||
}
|
||||
settled = true;
|
||||
clearTimeout(timer);
|
||||
resolve({ stdout, stderr, code, signal, killed: child.killed });
|
||||
|
||||
@@ -32,14 +32,24 @@ export function resolveCommandStdio(params: {
|
||||
}
|
||||
|
||||
export function formatSpawnError(err: unknown): string {
|
||||
if (!(err instanceof Error)) return String(err);
|
||||
if (!(err instanceof Error)) {
|
||||
return String(err);
|
||||
}
|
||||
const details = err as NodeJS.ErrnoException;
|
||||
const parts: string[] = [];
|
||||
const message = err.message?.trim();
|
||||
if (message) parts.push(message);
|
||||
if (details.code && !message?.includes(details.code)) parts.push(details.code);
|
||||
if (details.syscall) parts.push(`syscall=${details.syscall}`);
|
||||
if (typeof details.errno === "number") parts.push(`errno=${details.errno}`);
|
||||
if (message) {
|
||||
parts.push(message);
|
||||
}
|
||||
if (details.code && !message?.includes(details.code)) {
|
||||
parts.push(details.code);
|
||||
}
|
||||
if (details.syscall) {
|
||||
parts.push(`syscall=${details.syscall}`);
|
||||
}
|
||||
if (typeof details.errno === "number") {
|
||||
parts.push(`errno=${details.errno}`);
|
||||
}
|
||||
return parts.join(" ");
|
||||
}
|
||||
|
||||
@@ -63,13 +73,17 @@ async function spawnAndWaitForSpawn(
|
||||
child.removeListener("spawn", onSpawn);
|
||||
};
|
||||
const finishResolve = () => {
|
||||
if (settled) return;
|
||||
if (settled) {
|
||||
return;
|
||||
}
|
||||
settled = true;
|
||||
cleanup();
|
||||
resolve(child);
|
||||
};
|
||||
const onError = (err: unknown) => {
|
||||
if (settled) return;
|
||||
if (settled) {
|
||||
return;
|
||||
}
|
||||
settled = true;
|
||||
cleanup();
|
||||
reject(err);
|
||||
|
||||
Reference in New Issue
Block a user