mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 13:11:40 +00:00
refactor: dedupe core error formatting call sites
This commit is contained in:
@@ -2,6 +2,7 @@ import type { OpenClawConfig } from "../config/config.js";
|
||||
import { resolveSecretInputRef } from "../config/types.secrets.js";
|
||||
import { callGateway } from "../gateway/call.js";
|
||||
import { validateSecretsResolveResult } from "../gateway/protocol/index.js";
|
||||
import { formatErrorMessage } from "../infra/errors.js";
|
||||
import { resolveManifestContractOwnerPluginId } from "../plugins/manifest-registry.js";
|
||||
import {
|
||||
analyzeCommandSecretAssignmentsFromSnapshot,
|
||||
@@ -13,7 +14,6 @@ import { collectConfigAssignments } from "../secrets/runtime-config-collectors.j
|
||||
import { createResolverContext } from "../secrets/runtime-shared.js";
|
||||
import { resolveRuntimeWebTools } from "../secrets/runtime-web-tools.js";
|
||||
import { assertExpectedResolvedSecretValue } from "../secrets/secret-value.js";
|
||||
import { describeUnknownError } from "../secrets/shared.js";
|
||||
import {
|
||||
discoverConfigSecretTargetsByIds,
|
||||
type DiscoveredConfigSecretTarget,
|
||||
@@ -398,7 +398,7 @@ function collectInactiveSurfacePathsFromDiagnostics(diagnostics: string[]): Set<
|
||||
}
|
||||
|
||||
function isUnsupportedSecretsResolveError(err: unknown): boolean {
|
||||
const message = describeUnknownError(err).toLowerCase();
|
||||
const message = formatErrorMessage(err).toLowerCase();
|
||||
if (!message.includes("secrets.resolve")) {
|
||||
return false;
|
||||
}
|
||||
@@ -460,7 +460,7 @@ async function resolveCommandSecretRefsLocally(params: {
|
||||
throw error;
|
||||
}
|
||||
localResolutionDiagnostics.push(
|
||||
`${params.commandName}: failed to resolve web tool secrets locally (${describeUnknownError(error)}).`,
|
||||
`${params.commandName}: failed to resolve web tool secrets locally (${formatErrorMessage(error)}).`,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -650,7 +650,7 @@ async function resolveTargetSecretLocally(params: {
|
||||
} catch (error) {
|
||||
if (!enforcesResolvedSecrets(params.mode)) {
|
||||
params.localResolutionDiagnostics.push(
|
||||
`${params.commandName}: failed to resolve ${params.target.path} locally (${describeUnknownError(error)}).`,
|
||||
`${params.commandName}: failed to resolve ${params.target.path} locally (${formatErrorMessage(error)}).`,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -725,7 +725,7 @@ export async function resolveCommandSecretRefsViaGateway(params: {
|
||||
resolvedConfig: fallback.resolvedConfig,
|
||||
diagnostics: dedupeDiagnostics([
|
||||
...fallback.diagnostics,
|
||||
`${params.commandName}: gateway secrets.resolve unavailable (${describeUnknownError(err)}); ${fallbackMessage}`,
|
||||
`${params.commandName}: gateway secrets.resolve unavailable (${formatErrorMessage(err)}); ${fallbackMessage}`,
|
||||
]),
|
||||
targetStatesByPath: fallback.targetStatesByPath,
|
||||
hadUnresolvedTargets: fallback.hadUnresolvedTargets,
|
||||
@@ -735,12 +735,12 @@ export async function resolveCommandSecretRefsViaGateway(params: {
|
||||
}
|
||||
if (isUnsupportedSecretsResolveError(err)) {
|
||||
throw new Error(
|
||||
`${params.commandName}: active gateway does not support secrets.resolve (${describeUnknownError(err)}). Update the gateway or run without SecretRefs.`,
|
||||
`${params.commandName}: active gateway does not support secrets.resolve (${formatErrorMessage(err)}). Update the gateway or run without SecretRefs.`,
|
||||
{ cause: err },
|
||||
);
|
||||
}
|
||||
throw new Error(
|
||||
`${params.commandName}: failed to resolve secrets from the active gateway snapshot (${describeUnknownError(err)}). Start the gateway and retry.`,
|
||||
`${params.commandName}: failed to resolve secrets from the active gateway snapshot (${formatErrorMessage(err)}). Start the gateway and retry.`,
|
||||
{ cause: err },
|
||||
);
|
||||
}
|
||||
@@ -757,7 +757,7 @@ export async function resolveCommandSecretRefsViaGateway(params: {
|
||||
} catch (err) {
|
||||
const path = pathSegments.join(".");
|
||||
throw new Error(
|
||||
`${params.commandName}: failed to apply resolved secret assignment at ${path} (${describeUnknownError(err)}).`,
|
||||
`${params.commandName}: failed to apply resolved secret assignment at ${path} (${formatErrorMessage(err)}).`,
|
||||
{ cause: err },
|
||||
);
|
||||
}
|
||||
@@ -837,7 +837,7 @@ export async function resolveCommandSecretRefsViaGateway(params: {
|
||||
scrubUnresolvedAssignments(resolvedConfig, analyzed.unresolved);
|
||||
diagnostics = dedupeDiagnostics([
|
||||
...diagnostics,
|
||||
`${params.commandName}: local fallback after incomplete gateway snapshot failed (${describeUnknownError(error)}).`,
|
||||
`${params.commandName}: local fallback after incomplete gateway snapshot failed (${formatErrorMessage(error)}).`,
|
||||
...buildUnresolvedDiagnostics(params.commandName, analyzed.unresolved, mode),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import fs from "node:fs/promises";
|
||||
import type { Command } from "commander";
|
||||
import JSON5 from "json5";
|
||||
import { readBestEffortConfig, type OpenClawConfig } from "../config/config.js";
|
||||
import { formatErrorMessage } from "../infra/errors.js";
|
||||
import {
|
||||
collectExecPolicyScopeSnapshots,
|
||||
type ExecPolicyScopeSnapshot,
|
||||
@@ -17,7 +18,6 @@ import { defaultRuntime } from "../runtime.js";
|
||||
import { formatDocsLink } from "../terminal/links.js";
|
||||
import { getTerminalTableWidth, renderTable } from "../terminal/table.js";
|
||||
import { isRich, theme } from "../terminal/theme.js";
|
||||
import { describeUnknownError } from "./gateway-cli/shared.js";
|
||||
import { callGatewayFromCli } from "./gateway-rpc.js";
|
||||
import { nodesCallOpts, resolveNodeId } from "./nodes-cli/rpc.js";
|
||||
import type { NodesRpcOpts } from "./nodes-cli/types.js";
|
||||
@@ -157,7 +157,7 @@ async function saveSnapshotTargeted(params: {
|
||||
}
|
||||
|
||||
function formatCliError(err: unknown): string {
|
||||
const msg = describeUnknownError(err);
|
||||
const msg = formatErrorMessage(err);
|
||||
return msg.includes("\n") ? msg.split("\n")[0] : msg;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ import { withProgress } from "../progress.js";
|
||||
import { ensureDevGatewayConfig } from "./dev.js";
|
||||
import { runGatewayLoop } from "./run-loop.js";
|
||||
import {
|
||||
describeUnknownError,
|
||||
extractGatewayMiskeys,
|
||||
maybeExplainGatewayServiceStop,
|
||||
parsePort,
|
||||
@@ -559,7 +558,7 @@ async function runGatewayCommand(opts: GatewayRunOpts) {
|
||||
}
|
||||
} catch (err) {
|
||||
if (isGatewayLockError(err)) {
|
||||
const errMessage = describeUnknownError(err);
|
||||
const errMessage = formatErrorMessage(err);
|
||||
defaultRuntime.error(
|
||||
`Gateway failed to start: ${errMessage}\nIf the gateway is supervised, stop it with: ${formatCliCommand("openclaw gateway stop")}`,
|
||||
);
|
||||
|
||||
@@ -4,7 +4,6 @@ import {
|
||||
resolveGatewayWindowsTaskName,
|
||||
} from "../../daemon/constants.js";
|
||||
import { resolveGatewayService } from "../../daemon/service.js";
|
||||
import { formatErrorMessage } from "../../infra/errors.js";
|
||||
import { defaultRuntime } from "../../runtime.js";
|
||||
import { formatCliCommand } from "../command-format.js";
|
||||
import { parsePort } from "../shared/parse-port.js";
|
||||
@@ -21,10 +20,6 @@ export const toOptionString = (value: unknown): string | undefined => {
|
||||
return undefined;
|
||||
};
|
||||
|
||||
export function describeUnknownError(err: unknown): string {
|
||||
return formatErrorMessage(err);
|
||||
}
|
||||
|
||||
export function extractGatewayMiskeys(parsed: unknown): {
|
||||
hasGatewayToken: boolean;
|
||||
hasRemoteToken: boolean;
|
||||
|
||||
Reference in New Issue
Block a user