refactor: dedupe probe error formatting

This commit is contained in:
Peter Steinberger
2026-04-07 01:10:35 +01:00
parent 533bd00001
commit 325ff24bae
12 changed files with 25 additions and 13 deletions

View File

@@ -1,4 +1,5 @@
import crypto from "node:crypto";
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
import { fetchWithSsrFGuard } from "../runtime-api.js";
import type { ResolvedGoogleChatAccount } from "./accounts.js";
import { getGoogleChatAccessToken } from "./auth.js";
@@ -313,7 +314,7 @@ export async function probeGoogleChat(account: ResolvedGoogleChatAccount): Promi
} catch (err) {
return {
ok: false,
error: err instanceof Error ? err.message : String(err),
error: formatErrorMessage(err),
};
}
}

View File

@@ -1,4 +1,5 @@
import { messagingApi } from "@line/bot-sdk";
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
import { withTimeout } from "openclaw/plugin-sdk/text-runtime";
import type { LineProbeResult } from "./types.js";
@@ -27,7 +28,7 @@ export async function probeLineBot(
},
};
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
const message = formatErrorMessage(err);
return { ok: false, error: message };
}
}

View File

@@ -1,4 +1,4 @@
import type { PinnedDispatcherPolicy } from "openclaw/plugin-sdk/infra-runtime";
import { formatErrorMessage, type PinnedDispatcherPolicy } from "openclaw/plugin-sdk/infra-runtime";
import type { SsrFPolicy } from "../runtime-api.js";
import type { BaseProbeResult } from "../runtime-api.js";
import { isBunRuntime } from "./client/runtime.js";
@@ -88,7 +88,7 @@ export async function probeMatrix(params: {
typeof err === "object" && err && "statusCode" in err
? Number((err as { statusCode?: number }).statusCode)
: result.status,
error: err instanceof Error ? err.message : String(err),
error: formatErrorMessage(err),
elapsedMs: Date.now() - started,
};
}

View File

@@ -1,3 +1,4 @@
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
import {
fetchWithSsrFGuard,
ssrfPolicyFromPrivateNetworkOptIn,
@@ -60,7 +61,7 @@ export async function probeMattermost(
await release();
}
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
const message = formatErrorMessage(err);
return {
ok: false,
status: null,

View File

@@ -1,4 +1,5 @@
import { readFileSync } from "node:fs";
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
import { ssrfPolicyFromPrivateNetworkOptIn } from "openclaw/plugin-sdk/ssrf-runtime";
import { fetchWithSsrFGuard, type RuntimeEnv } from "../runtime-api.js";
import type { ResolvedNextcloudTalkAccount } from "./accounts.js";
@@ -139,7 +140,7 @@ export async function resolveNextcloudTalkRoomKind(params: {
} catch (err) {
roomCache.set(key, {
fetchedAt: Date.now(),
error: err instanceof Error ? err.message : String(err),
error: formatErrorMessage(err),
});
runtime?.error?.(`nextcloud-talk: room lookup error: ${String(err)}`);
return undefined;

View File

@@ -1,4 +1,5 @@
import type { BaseProbeResult } from "openclaw/plugin-sdk/channel-contract";
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
import { withTimeout } from "openclaw/plugin-sdk/text-runtime";
import { createSlackWebClient } from "./client.js";
@@ -30,7 +31,7 @@ export async function probeSlack(token: string, timeoutMs = 2500): Promise<Slack
team: { id: result.team_id, name: result.team },
};
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
const message = formatErrorMessage(err);
const status =
typeof (err as { status?: number }).status === "number"
? (err as { status?: number }).status

View File

@@ -1,4 +1,5 @@
import { createRequire } from "node:module";
import { formatErrorMessage } from "./errors.js";
import { installProcessWarningFilter } from "./warning-filter.js";
const require = createRequire(import.meta.url);
@@ -8,7 +9,7 @@ export function requireNodeSqlite(): typeof import("node:sqlite") {
try {
return require("node:sqlite") as typeof import("node:sqlite");
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
const message = formatErrorMessage(err);
throw new Error(
`SQLite support is unavailable in this Node runtime (missing node:sqlite). ${message}`,
{ cause: err },

View File

@@ -1,3 +1,5 @@
import { formatErrorMessage } from "../../infra/errors.js";
type BatchOutputErrorLike = {
error?: { message?: string };
response?: {
@@ -26,6 +28,6 @@ export function extractBatchErrorMessage(lines: BatchOutputErrorLike[]): string
}
export function formatUnavailableBatchError(err: unknown): string | undefined {
const message = err instanceof Error ? err.message : String(err);
const message = formatErrorMessage(err);
return message ? `error file unavailable: ${message}` : undefined;
}

View File

@@ -1,4 +1,5 @@
import type { DatabaseSync } from "node:sqlite";
import { formatErrorMessage } from "../../infra/errors.js";
export function ensureMemoryIndexSchema(params: {
db: DatabaseSync;
@@ -74,7 +75,7 @@ export function ensureMemoryIndexSchema(params: {
);
ftsAvailable = true;
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
const message = formatErrorMessage(err);
ftsAvailable = false;
ftsError = message;
}

View File

@@ -1,3 +1,4 @@
import { formatErrorMessage } from "../../infra/errors.js";
import { createSubsystemLogger } from "../../logging/subsystem.js";
const log = createSubsystemLogger("memory");
@@ -42,7 +43,7 @@ export function parseQmdQueryJson(stdout: string, stderr: string): QmdQueryResul
}
throw new Error("qmd query JSON response was not an array");
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
const message = formatErrorMessage(err);
log.warn(`qmd query returned invalid JSON: ${message}`);
throw new Error(`qmd query returned invalid JSON: ${message}`, { cause: err });
}

View File

@@ -1,4 +1,5 @@
import type { DatabaseSync } from "node:sqlite";
import { formatErrorMessage } from "../../infra/errors.js";
export async function loadSqliteVecExtension(params: {
db: DatabaseSync;
@@ -18,7 +19,7 @@ export async function loadSqliteVecExtension(params: {
return { ok: true, extensionPath };
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
const message = formatErrorMessage(err);
return { ok: false, error: message };
}
}

View File

@@ -1,4 +1,5 @@
import { createRequire } from "node:module";
import { formatErrorMessage } from "../../infra/errors.js";
import { installProcessWarningFilter } from "../../infra/warning-filter.js";
const require = createRequire(import.meta.url);
@@ -8,7 +9,7 @@ export function requireNodeSqlite(): typeof import("node:sqlite") {
try {
return require("node:sqlite") as typeof import("node:sqlite");
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
const message = formatErrorMessage(err);
// Node distributions can ship without the experimental builtin SQLite module.
// Surface an actionable error instead of the generic "unknown builtin module".
throw new Error(