mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 09:41:11 +00:00
refactor: dedupe core helper error formatting
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import type { Command } from "commander";
|
||||
import { formatErrorMessage } from "../../infra/errors.js";
|
||||
import { formatTimeAgo } from "../../infra/format-time/format-relative.ts";
|
||||
import { defaultRuntime } from "../../runtime.js";
|
||||
import { getTerminalTableWidth, renderTable } from "../../terminal/table.js";
|
||||
@@ -99,7 +100,7 @@ function parseSinceMs(raw: unknown, label: string): number | undefined {
|
||||
try {
|
||||
return parseDurationMs(value);
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : String(err);
|
||||
const message = formatErrorMessage(err);
|
||||
defaultRuntime.error(`${label}: ${message}`);
|
||||
defaultRuntime.exit(1);
|
||||
return undefined;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { execFileSync } from "node:child_process";
|
||||
import { createServer } from "node:net";
|
||||
import { formatErrorMessage } from "../infra/errors.js";
|
||||
import { resolveLsofCommandSync } from "../infra/ports-lsof.js";
|
||||
import { tryListenOnPort } from "../infra/ports-probe.js";
|
||||
import { sleep } from "../utils.js";
|
||||
@@ -64,7 +65,7 @@ function isRecoverableLsofError(err: unknown): boolean {
|
||||
if (code === "ENOENT" || code === "EACCES" || code === "EPERM") {
|
||||
return true;
|
||||
}
|
||||
const message = err instanceof Error ? err.message : String(err);
|
||||
const message = formatErrorMessage(err);
|
||||
return /lsof.*(permission denied|not permitted|operation not permitted|eacces|eperm)/i.test(
|
||||
message,
|
||||
);
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { OpenClawConfig } from "../config/config.js";
|
||||
import { buildGatewayConnectionDetails, callGateway } from "../gateway/call.js";
|
||||
import type { DoctorMemoryStatusPayload } from "../gateway/server-methods/doctor.js";
|
||||
import { collectChannelStatusIssues } from "../infra/channels-status-issues.js";
|
||||
import { formatErrorMessage } from "../infra/errors.js";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import { note } from "../terminal/note.js";
|
||||
import { formatHealthCheckFailure } from "./health-format.js";
|
||||
@@ -82,7 +83,7 @@ export async function probeGatewayMemoryStatus(params: {
|
||||
error: payload.embedding.error,
|
||||
};
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : String(err);
|
||||
const message = formatErrorMessage(err);
|
||||
return {
|
||||
checked: true,
|
||||
ready: false,
|
||||
|
||||
@@ -26,6 +26,7 @@ import type {
|
||||
import type { ChannelChoice } from "../commands/onboard-types.js";
|
||||
import { isChannelConfigured } from "../config/channel-configured.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { formatErrorMessage } from "../infra/errors.js";
|
||||
import { enablePluginInConfig } from "../plugins/enable.js";
|
||||
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "../routing/session-key.js";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
@@ -68,7 +69,7 @@ export async function runCollectedChannelOnboardingPostWriteHooks(params: {
|
||||
try {
|
||||
await hook.run({ cfg: params.cfg, runtime: params.runtime });
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : String(err);
|
||||
const message = formatErrorMessage(err);
|
||||
params.runtime.error(
|
||||
`Channel ${hook.channel} post-setup warning for "${hook.accountId}": ${message}`,
|
||||
);
|
||||
|
||||
@@ -27,6 +27,7 @@ import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { resolveStateDir } from "../../../config/paths.js";
|
||||
import { formatErrorMessage } from "../../../infra/errors.js";
|
||||
import { createSubsystemLogger } from "../../../logging/subsystem.js";
|
||||
import type { HookHandler } from "../../hooks.js";
|
||||
|
||||
@@ -60,7 +61,7 @@ const logCommand: HookHandler = async (event) => {
|
||||
|
||||
await fs.appendFile(logFile, logLine, "utf-8");
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : String(err);
|
||||
const message = formatErrorMessage(err);
|
||||
log.error(`Failed to log command: ${message}`);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -10,6 +10,7 @@ import type { CliDeps } from "../cli/deps.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import type { SessionEntry } from "../config/sessions.js";
|
||||
import type { SessionsPatchParams } from "../gateway/protocol/index.js";
|
||||
import { formatErrorMessage } from "../infra/errors.js";
|
||||
import { createSubsystemLogger } from "../logging/subsystem.js";
|
||||
import { resolveGlobalSingleton } from "../shared/global-singleton.js";
|
||||
|
||||
@@ -299,7 +300,7 @@ export async function triggerInternalHook(event: InternalHookEvent): Promise<voi
|
||||
try {
|
||||
await handler(event);
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : String(err);
|
||||
const message = formatErrorMessage(err);
|
||||
log.error(`Hook error [${event.type}:${event.action}]: ${message}`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user