From 77a161c811183cca5488a606f5fdfa31f4e359f0 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 7 Apr 2026 01:15:34 +0100 Subject: [PATCH] refactor: dedupe provider bootstrap error formatting --- extensions/matrix/index.ts | 5 +++-- extensions/matrix/src/matrix/deps.ts | 3 ++- extensions/memory-wiki/src/gateway.ts | 3 ++- extensions/microsoft-foundry/onboard.ts | 3 ++- extensions/microsoft-foundry/runtime.ts | 3 ++- extensions/minimax/index.ts | 3 ++- extensions/nostr/src/nostr-profile.ts | 3 ++- extensions/openai/openai-codex-provider.ts | 3 ++- extensions/signal/src/install-signal-cli.ts | 3 ++- 9 files changed, 19 insertions(+), 10 deletions(-) diff --git a/extensions/matrix/index.ts b/extensions/matrix/index.ts index b7e868f2c5e..0bf159a8434 100644 --- a/extensions/matrix/index.ts +++ b/extensions/matrix/index.ts @@ -1,4 +1,5 @@ import { defineBundledChannelEntry } from "openclaw/plugin-sdk/channel-entry-contract"; +import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime"; import { registerMatrixCliMetadata } from "./cli-metadata.js"; export default defineBundledChannelEntry({ @@ -23,12 +24,12 @@ export default defineBundledChannelEntry({ void import("./plugin-entry.handlers.runtime.js") .then(({ ensureMatrixCryptoRuntime }) => ensureMatrixCryptoRuntime({ log: api.logger.info }).catch((err: unknown) => { - const message = err instanceof Error ? err.message : String(err); + const message = formatErrorMessage(err); api.logger.warn?.(`matrix: crypto runtime bootstrap failed: ${message}`); }), ) .catch((err: unknown) => { - const message = err instanceof Error ? err.message : String(err); + const message = formatErrorMessage(err); api.logger.warn?.(`matrix: failed loading crypto bootstrap runtime: ${message}`); }); diff --git a/extensions/matrix/src/matrix/deps.ts b/extensions/matrix/src/matrix/deps.ts index db21d4777ab..0324c61af00 100644 --- a/extensions/matrix/src/matrix/deps.ts +++ b/extensions/matrix/src/matrix/deps.ts @@ -3,6 +3,7 @@ import fs from "node:fs"; import { createRequire } from "node:module"; import path from "node:path"; import { fileURLToPath } from "node:url"; +import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime"; import type { RuntimeEnv } from "../runtime-api.js"; const REQUIRED_MATRIX_PACKAGES = [ @@ -137,7 +138,7 @@ function defaultResolveFn(id: string): string { } function isMissingMatrixCryptoRuntimeError(error: unknown): boolean { - const message = error instanceof Error ? error.message : String(error); + const message = formatErrorMessage(error); return ( message.includes("@matrix-org/matrix-sdk-crypto-nodejs-") || message.includes("matrix-sdk-crypto-nodejs") || diff --git a/extensions/memory-wiki/src/gateway.ts b/extensions/memory-wiki/src/gateway.ts index 734b46db444..5526a4401ce 100644 --- a/extensions/memory-wiki/src/gateway.ts +++ b/extensions/memory-wiki/src/gateway.ts @@ -1,3 +1,4 @@ +import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime"; import type { OpenClawConfig, OpenClawPluginApi } from "../api.js"; import { applyMemoryWikiMutation, normalizeMemoryWikiMutationInput } from "./apply.js"; import { compileMemoryWikiVault } from "./compile.js"; @@ -78,7 +79,7 @@ function readEnumParam( } function respondError(respond: GatewayRespond, error: unknown) { - const message = error instanceof Error ? error.message : String(error); + const message = formatErrorMessage(error); respond(false, undefined, { code: "internal_error", message }); } diff --git a/extensions/microsoft-foundry/onboard.ts b/extensions/microsoft-foundry/onboard.ts index 37fd2002a6b..a2a73379af2 100644 --- a/extensions/microsoft-foundry/onboard.ts +++ b/extensions/microsoft-foundry/onboard.ts @@ -1,4 +1,5 @@ import type { ProviderAuthContext } from "openclaw/plugin-sdk/core"; +import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime"; import { azLoginDeviceCode, azLoginDeviceCodeWithOptions, @@ -422,7 +423,7 @@ export async function loginWithTenantFallback( await azLoginDeviceCode(); return { account: getLoggedInAccount() }; } catch (error) { - const message = error instanceof Error ? error.message : String(error); + const message = formatErrorMessage(error); const isAzureTenantError = /AADSTS\d+/i.test(message) || /no subscriptions found/i.test(message) || diff --git a/extensions/microsoft-foundry/runtime.ts b/extensions/microsoft-foundry/runtime.ts index 806bf0dacd2..b094f7a0a0d 100644 --- a/extensions/microsoft-foundry/runtime.ts +++ b/extensions/microsoft-foundry/runtime.ts @@ -1,4 +1,5 @@ import type { ProviderPrepareRuntimeAuthContext } from "openclaw/plugin-sdk/core"; +import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime"; import { ensureAuthProfileStore } from "openclaw/plugin-sdk/provider-auth"; import { getAccessTokenResultAsync } from "./cli.js"; import { @@ -95,7 +96,7 @@ export async function prepareFoundryRuntimeAuth(ctx: ProviderPrepareRuntimeAuthC ...(baseUrl ? { baseUrl } : {}), }; } catch (err) { - const details = err instanceof Error ? err.message : String(err); + const details = formatErrorMessage(err); throw new Error(`Failed to refresh Azure Entra ID token via az CLI: ${details}`, { cause: err, }); diff --git a/extensions/minimax/index.ts b/extensions/minimax/index.ts index 7b219e9b47b..2adf627c879 100644 --- a/extensions/minimax/index.ts +++ b/extensions/minimax/index.ts @@ -1,3 +1,4 @@ +import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime"; import { definePluginEntry, type ProviderAuthContext, @@ -169,7 +170,7 @@ function createOAuthHandler(region: MiniMaxRegion) { ], }); } catch (err) { - const errorMsg = err instanceof Error ? err.message : String(err); + const errorMsg = formatErrorMessage(err); progress.stop(`MiniMax OAuth failed: ${errorMsg}`); await ctx.prompter.note( "If OAuth fails, verify your MiniMax account has portal access and try again.", diff --git a/extensions/nostr/src/nostr-profile.ts b/extensions/nostr/src/nostr-profile.ts index 039c8a19a3d..251c86cc859 100644 --- a/extensions/nostr/src/nostr-profile.ts +++ b/extensions/nostr/src/nostr-profile.ts @@ -6,6 +6,7 @@ */ import { finalizeEvent, SimplePool, type Event } from "nostr-tools"; +import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime"; import { type NostrProfile, NostrProfileSchema } from "./config-schema.js"; // ============================================================================ @@ -186,7 +187,7 @@ export async function publishProfileEvent( successes.push(relay); } catch (err) { - const errorMessage = err instanceof Error ? err.message : String(err); + const errorMessage = formatErrorMessage(err); failures.push({ relay, error: errorMessage }); } }); diff --git a/extensions/openai/openai-codex-provider.ts b/extensions/openai/openai-codex-provider.ts index aeb6ef12a8b..9d5164c3dd4 100644 --- a/extensions/openai/openai-codex-provider.ts +++ b/extensions/openai/openai-codex-provider.ts @@ -1,3 +1,4 @@ +import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime"; import type { ProviderAuthContext, ProviderResolveDynamicModelContext, @@ -182,7 +183,7 @@ async function refreshOpenAICodexOAuthCredential(cred: OAuthCredential) { displayName: cred.displayName, }; } catch (error) { - const message = error instanceof Error ? error.message : String(error); + const message = formatErrorMessage(error); if ( /extract\s+accountid\s+from\s+token/i.test(message) && typeof cred.access === "string" && diff --git a/extensions/signal/src/install-signal-cli.ts b/extensions/signal/src/install-signal-cli.ts index bd79d40177a..fbbc5908a34 100644 --- a/extensions/signal/src/install-signal-cli.ts +++ b/extensions/signal/src/install-signal-cli.ts @@ -4,6 +4,7 @@ import { request } from "node:https"; import os from "node:os"; import path from "node:path"; import { pipeline } from "node:stream/promises"; +import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime"; import { runPluginCommandWithTimeout } from "openclaw/plugin-sdk/run-command"; import type { RuntimeEnv } from "openclaw/plugin-sdk/runtime-env"; import { CONFIG_DIR, extractArchive, resolveBrewExecutable } from "openclaw/plugin-sdk/setup-tools"; @@ -258,7 +259,7 @@ async function installSignalCliFromRelease(runtime: RuntimeEnv): Promise