BYPASS SHELL BY ./RAZORGANZ
Server: nginx/1.20.1
System: Linux iZdzfnv9mwfppeZ 5.10.134-19.2.al8.x86_64 #1 SMP Wed Oct 29 22:47:09 CST 2025 x86_64
User: apache (48)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //lib/node_modules/openclaw/dist/diagnostics-BBskTZVP.js
import { s as resolveGatewayLogPaths } from "./service-DGTWp5Hg.js";
import fs from "node:fs/promises";

//#region src/daemon/diagnostics.ts
const GATEWAY_LOG_ERROR_PATTERNS = [
	/refusing to bind gateway/i,
	/gateway auth mode/i,
	/gateway start blocked/i,
	/failed to bind gateway socket/i,
	/tailscale .* requires/i
];
async function readLastLogLine(filePath) {
	try {
		const lines = (await fs.readFile(filePath, "utf8")).split(/\r?\n/).map((line) => line.trim());
		for (let i = lines.length - 1; i >= 0; i -= 1) if (lines[i]) return lines[i];
		return null;
	} catch {
		return null;
	}
}
async function readLastGatewayErrorLine(env) {
	const { stdoutPath, stderrPath } = resolveGatewayLogPaths(env);
	const stderrRaw = await fs.readFile(stderrPath, "utf8").catch(() => "");
	const stdoutRaw = await fs.readFile(stdoutPath, "utf8").catch(() => "");
	const lines = [...stderrRaw.split(/\r?\n/), ...stdoutRaw.split(/\r?\n/)].map((line) => line.trim());
	for (let i = lines.length - 1; i >= 0; i -= 1) {
		const line = lines[i];
		if (!line) continue;
		if (GATEWAY_LOG_ERROR_PATTERNS.some((pattern) => pattern.test(line))) return line;
	}
	return await readLastLogLine(stderrPath) ?? await readLastLogLine(stdoutPath);
}

//#endregion
export { readLastGatewayErrorLine as t };