chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -30,7 +30,9 @@ export async function runDaemonInstall(opts: DaemonInstallOptions) {
|
||||
hints?: string[];
|
||||
warnings?: string[];
|
||||
}) => {
|
||||
if (!json) return;
|
||||
if (!json) {
|
||||
return;
|
||||
}
|
||||
emitDaemonActionJson({ action: "install", ...payload });
|
||||
};
|
||||
const fail = (message: string) => {
|
||||
@@ -97,8 +99,11 @@ export async function runDaemonInstall(opts: DaemonInstallOptions) {
|
||||
token: opts.token || cfg.gateway?.auth?.token || process.env.OPENCLAW_GATEWAY_TOKEN,
|
||||
runtime: runtimeRaw,
|
||||
warn: (message) => {
|
||||
if (json) warnings.push(message);
|
||||
else defaultRuntime.log(message);
|
||||
if (json) {
|
||||
warnings.push(message);
|
||||
} else {
|
||||
defaultRuntime.log(message);
|
||||
}
|
||||
},
|
||||
config: cfg,
|
||||
});
|
||||
|
||||
@@ -23,12 +23,17 @@ export async function runDaemonUninstall(opts: DaemonLifecycleOptions = {}) {
|
||||
notLoadedText: string;
|
||||
};
|
||||
}) => {
|
||||
if (!json) return;
|
||||
if (!json) {
|
||||
return;
|
||||
}
|
||||
emitDaemonActionJson({ action: "uninstall", ...payload });
|
||||
};
|
||||
const fail = (message: string) => {
|
||||
if (json) emit({ ok: false, error: message });
|
||||
else defaultRuntime.error(message);
|
||||
if (json) {
|
||||
emit({ ok: false, error: message });
|
||||
} else {
|
||||
defaultRuntime.error(message);
|
||||
}
|
||||
defaultRuntime.exit(1);
|
||||
};
|
||||
|
||||
@@ -91,12 +96,17 @@ export async function runDaemonStart(opts: DaemonLifecycleOptions = {}) {
|
||||
notLoadedText: string;
|
||||
};
|
||||
}) => {
|
||||
if (!json) return;
|
||||
if (!json) {
|
||||
return;
|
||||
}
|
||||
emitDaemonActionJson({ action: "start", ...payload });
|
||||
};
|
||||
const fail = (message: string, hints?: string[]) => {
|
||||
if (json) emit({ ok: false, error: message, hints });
|
||||
else defaultRuntime.error(message);
|
||||
if (json) {
|
||||
emit({ ok: false, error: message, hints });
|
||||
} else {
|
||||
defaultRuntime.error(message);
|
||||
}
|
||||
defaultRuntime.exit(1);
|
||||
};
|
||||
|
||||
@@ -167,12 +177,17 @@ export async function runDaemonStop(opts: DaemonLifecycleOptions = {}) {
|
||||
notLoadedText: string;
|
||||
};
|
||||
}) => {
|
||||
if (!json) return;
|
||||
if (!json) {
|
||||
return;
|
||||
}
|
||||
emitDaemonActionJson({ action: "stop", ...payload });
|
||||
};
|
||||
const fail = (message: string) => {
|
||||
if (json) emit({ ok: false, error: message });
|
||||
else defaultRuntime.error(message);
|
||||
if (json) {
|
||||
emit({ ok: false, error: message });
|
||||
} else {
|
||||
defaultRuntime.error(message);
|
||||
}
|
||||
defaultRuntime.exit(1);
|
||||
};
|
||||
|
||||
@@ -237,12 +252,17 @@ export async function runDaemonRestart(opts: DaemonLifecycleOptions = {}): Promi
|
||||
notLoadedText: string;
|
||||
};
|
||||
}) => {
|
||||
if (!json) return;
|
||||
if (!json) {
|
||||
return;
|
||||
}
|
||||
emitDaemonActionJson({ action: "restart", ...payload });
|
||||
};
|
||||
const fail = (message: string, hints?: string[]) => {
|
||||
if (json) emit({ ok: false, error: message, hints });
|
||||
else defaultRuntime.error(message);
|
||||
if (json) {
|
||||
emit({ ok: false, error: message, hints });
|
||||
} else {
|
||||
defaultRuntime.error(message);
|
||||
}
|
||||
defaultRuntime.exit(1);
|
||||
};
|
||||
|
||||
|
||||
@@ -8,31 +8,43 @@ import { getResolvedLoggerSettings } from "../../logging.js";
|
||||
import { formatCliCommand } from "../command-format.js";
|
||||
|
||||
export function parsePort(raw: unknown): number | null {
|
||||
if (raw === undefined || raw === null) return null;
|
||||
if (raw === undefined || raw === null) {
|
||||
return null;
|
||||
}
|
||||
const value =
|
||||
typeof raw === "string"
|
||||
? raw
|
||||
: typeof raw === "number" || typeof raw === "bigint"
|
||||
? raw.toString()
|
||||
: null;
|
||||
if (value === null) return null;
|
||||
if (value === null) {
|
||||
return null;
|
||||
}
|
||||
const parsed = Number.parseInt(value, 10);
|
||||
if (!Number.isFinite(parsed) || parsed <= 0) return null;
|
||||
if (!Number.isFinite(parsed) || parsed <= 0) {
|
||||
return null;
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
|
||||
export function parsePortFromArgs(programArguments: string[] | undefined): number | null {
|
||||
if (!programArguments?.length) return null;
|
||||
if (!programArguments?.length) {
|
||||
return null;
|
||||
}
|
||||
for (let i = 0; i < programArguments.length; i += 1) {
|
||||
const arg = programArguments[i];
|
||||
if (arg === "--port") {
|
||||
const next = programArguments[i + 1];
|
||||
const parsed = parsePort(next);
|
||||
if (parsed) return parsed;
|
||||
if (parsed) {
|
||||
return parsed;
|
||||
}
|
||||
}
|
||||
if (arg?.startsWith("--port=")) {
|
||||
const parsed = parsePort(arg.split("=", 2)[1]);
|
||||
if (parsed) return parsed;
|
||||
if (parsed) {
|
||||
return parsed;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -46,7 +58,9 @@ export function pickProbeHostForBind(
|
||||
if (bindMode === "custom" && customBindHost?.trim()) {
|
||||
return customBindHost.trim();
|
||||
}
|
||||
if (bindMode === "tailnet") return tailnetIPv4 ?? "127.0.0.1";
|
||||
if (bindMode === "tailnet") {
|
||||
return tailnetIPv4 ?? "127.0.0.1";
|
||||
}
|
||||
return "127.0.0.1";
|
||||
}
|
||||
|
||||
@@ -59,11 +73,15 @@ const SAFE_DAEMON_ENV_KEYS = [
|
||||
];
|
||||
|
||||
export function filterDaemonEnv(env: Record<string, string> | undefined): Record<string, string> {
|
||||
if (!env) return {};
|
||||
if (!env) {
|
||||
return {};
|
||||
}
|
||||
const filtered: Record<string, string> = {};
|
||||
for (const key of SAFE_DAEMON_ENV_KEYS) {
|
||||
const value = env[key];
|
||||
if (!value?.trim()) continue;
|
||||
if (!value?.trim()) {
|
||||
continue;
|
||||
}
|
||||
filtered[key] = value.trim();
|
||||
}
|
||||
return filtered;
|
||||
@@ -76,7 +94,9 @@ export function safeDaemonEnv(env: Record<string, string> | undefined): string[]
|
||||
|
||||
export function normalizeListenerAddress(raw: string): string {
|
||||
let value = raw.trim();
|
||||
if (!value) return value;
|
||||
if (!value) {
|
||||
return value;
|
||||
}
|
||||
value = value.replace(/^TCP\s+/i, "");
|
||||
value = value.replace(/\s+\(LISTEN\)\s*$/i, "");
|
||||
return value.trim();
|
||||
@@ -97,21 +117,35 @@ export function formatRuntimeStatus(
|
||||
}
|
||||
| undefined,
|
||||
) {
|
||||
if (!runtime) return null;
|
||||
if (!runtime) {
|
||||
return null;
|
||||
}
|
||||
const status = runtime.status ?? "unknown";
|
||||
const details: string[] = [];
|
||||
if (runtime.pid) details.push(`pid ${runtime.pid}`);
|
||||
if (runtime.pid) {
|
||||
details.push(`pid ${runtime.pid}`);
|
||||
}
|
||||
if (runtime.state && runtime.state.toLowerCase() !== status) {
|
||||
details.push(`state ${runtime.state}`);
|
||||
}
|
||||
if (runtime.subState) details.push(`sub ${runtime.subState}`);
|
||||
if (runtime.subState) {
|
||||
details.push(`sub ${runtime.subState}`);
|
||||
}
|
||||
if (runtime.lastExitStatus !== undefined) {
|
||||
details.push(`last exit ${runtime.lastExitStatus}`);
|
||||
}
|
||||
if (runtime.lastExitReason) details.push(`reason ${runtime.lastExitReason}`);
|
||||
if (runtime.lastRunResult) details.push(`last run ${runtime.lastRunResult}`);
|
||||
if (runtime.lastRunTime) details.push(`last run time ${runtime.lastRunTime}`);
|
||||
if (runtime.detail) details.push(runtime.detail);
|
||||
if (runtime.lastExitReason) {
|
||||
details.push(`reason ${runtime.lastExitReason}`);
|
||||
}
|
||||
if (runtime.lastRunResult) {
|
||||
details.push(`last run ${runtime.lastRunResult}`);
|
||||
}
|
||||
if (runtime.lastRunTime) {
|
||||
details.push(`last run time ${runtime.lastRunTime}`);
|
||||
}
|
||||
if (runtime.detail) {
|
||||
details.push(runtime.detail);
|
||||
}
|
||||
return details.length > 0 ? `${status} (${details.join(", ")})` : status;
|
||||
}
|
||||
|
||||
@@ -119,7 +153,9 @@ export function renderRuntimeHints(
|
||||
runtime: { missingUnit?: boolean; status?: string } | undefined,
|
||||
env: NodeJS.ProcessEnv = process.env,
|
||||
): string[] {
|
||||
if (!runtime) return [];
|
||||
if (!runtime) {
|
||||
return [];
|
||||
}
|
||||
const hints: string[] = [];
|
||||
const fileLog = (() => {
|
||||
try {
|
||||
@@ -130,11 +166,15 @@ export function renderRuntimeHints(
|
||||
})();
|
||||
if (runtime.missingUnit) {
|
||||
hints.push(`Service not installed. Run: ${formatCliCommand("openclaw gateway install", env)}`);
|
||||
if (fileLog) hints.push(`File logs: ${fileLog}`);
|
||||
if (fileLog) {
|
||||
hints.push(`File logs: ${fileLog}`);
|
||||
}
|
||||
return hints;
|
||||
}
|
||||
if (runtime.status === "stopped") {
|
||||
if (fileLog) hints.push(`File logs: ${fileLog}`);
|
||||
if (fileLog) {
|
||||
hints.push(`File logs: ${fileLog}`);
|
||||
}
|
||||
if (process.platform === "darwin") {
|
||||
const logs = resolveGatewayLogPaths(env);
|
||||
hints.push(`Launchd stdout (if installed): ${logs.stdoutPath}`);
|
||||
|
||||
@@ -96,8 +96,12 @@ export type DaemonStatus = {
|
||||
};
|
||||
|
||||
function shouldReportPortUsage(status: PortUsageStatus | undefined, rpcOk?: boolean) {
|
||||
if (status !== "busy") return false;
|
||||
if (rpcOk === true) return false;
|
||||
if (status !== "busy") {
|
||||
return false;
|
||||
}
|
||||
if (rpcOk === true) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -271,7 +275,9 @@ export async function gatherDaemonStatus(
|
||||
}
|
||||
|
||||
export function renderPortDiagnosticsForCli(status: DaemonStatus, rpcOk?: boolean): string[] {
|
||||
if (!status.port || !shouldReportPortUsage(status.port.status, rpcOk)) return [];
|
||||
if (!status.port || !shouldReportPortUsage(status.port.status, rpcOk)) {
|
||||
return [];
|
||||
}
|
||||
return formatPortDiagnostics({
|
||||
port: status.port.port,
|
||||
status: status.port.status,
|
||||
|
||||
@@ -29,7 +29,9 @@ import {
|
||||
|
||||
function sanitizeDaemonStatusForJson(status: DaemonStatus): DaemonStatus {
|
||||
const command = status.service.command;
|
||||
if (!command?.environment) return status;
|
||||
if (!command?.environment) {
|
||||
return status;
|
||||
}
|
||||
const safeEnv = filterDaemonEnv(command.environment);
|
||||
const nextCommand = {
|
||||
...command,
|
||||
@@ -189,7 +191,9 @@ export function printDaemonStatus(status: DaemonStatus, opts: { json: boolean })
|
||||
defaultRuntime.log(`${label("RPC probe:")} ${okText("ok")}`);
|
||||
} else {
|
||||
defaultRuntime.error(`${label("RPC probe:")} ${errorText("failed")}`);
|
||||
if (rpc.url) defaultRuntime.error(`${label("RPC target:")} ${rpc.url}`);
|
||||
if (rpc.url) {
|
||||
defaultRuntime.error(`${label("RPC target:")} ${rpc.url}`);
|
||||
}
|
||||
const lines = String(rpc.error ?? "unknown")
|
||||
.split(/\r?\n/)
|
||||
.filter(Boolean);
|
||||
|
||||
Reference in New Issue
Block a user