refactor: dedupe core error formatting call sites

This commit is contained in:
Peter Steinberger
2026-04-07 04:05:23 +01:00
parent a03e430248
commit bbe9b7ba15
12 changed files with 34 additions and 53 deletions

View File

@@ -9,6 +9,7 @@ import { normalizeProviderId } from "../agents/model-selection.js";
import { resolveStateDir, type OpenClawConfig } from "../config/config.js";
import { coerceSecretRef } from "../config/types.secrets.js";
import { resolveSecretInputRef, type SecretRef } from "../config/types.secrets.js";
import { formatErrorMessage } from "../infra/errors.js";
import { resolveConfigDir, resolveUserPath } from "../utils.js";
import { runTasksWithConcurrency } from "../utils/run-with-concurrency.js";
import { iterateAuthProfileCredentials } from "./auth-profiles-scan.js";
@@ -27,7 +28,6 @@ import {
isExpectedResolvedSecretValue,
} from "./secret-value.js";
import { isNonEmptyString, isRecord } from "./shared.js";
import { describeUnknownError } from "./shared.js";
import {
listAgentModelsJsonPaths,
listAuthProfileStorePaths,
@@ -568,7 +568,7 @@ async function collectUnresolvedRefFindings(params: {
severity: "error",
file: assignment.file,
jsonPath: assignment.path,
message: `Failed to resolve ${assignment.ref.source}:${assignment.ref.provider}:${assignment.ref.id} (${describeUnknownError(resolveErr)}).`,
message: `Failed to resolve ${assignment.ref.source}:${assignment.ref.provider}:${assignment.ref.id} (${formatErrorMessage(resolveErr)}).`,
provider: assignment.provider,
});
continue;

View File

@@ -9,6 +9,7 @@ import type {
SecretRef,
SecretRefSource,
} from "../config/types.secrets.js";
import { formatErrorMessage } from "../infra/errors.js";
import { inspectPathPermissions, safeStat } from "../security/audit-fs.js";
import { isPathInside } from "../security/scan-paths.js";
import { resolveUserPath } from "../utils.js";
@@ -21,12 +22,7 @@ import {
resolveDefaultSecretProviderAlias,
secretRefKey,
} from "./ref-contract.js";
import {
describeUnknownError,
isNonEmptyString,
isRecord,
normalizePositiveInt,
} from "./shared.js";
import { isNonEmptyString, isRecord, normalizePositiveInt } from "./shared.js";
const DEFAULT_PROVIDER_CONCURRENCY = 4;
const DEFAULT_MAX_REFS_PER_PROVIDER = 512;
@@ -140,7 +136,7 @@ function throwUnknownProviderResolutionError(params: {
throw providerResolutionError({
source: params.source,
provider: params.provider,
message: describeUnknownError(params.err),
message: formatErrorMessage(params.err),
cause: params.err,
});
}
@@ -419,7 +415,7 @@ async function resolveFileRefs(params: {
source: "file",
provider: params.providerName,
refId: ref.id,
message: describeUnknownError(err),
message: formatErrorMessage(err),
cause: err,
});
}

View File

@@ -1,6 +1,5 @@
import fs from "node:fs";
import path from "node:path";
import { formatErrorMessage } from "../infra/errors.js";
export { isRecord } from "../utils.js";
export function isNonEmptyString(value: unknown): value is string {
@@ -60,7 +59,3 @@ export function writeTextFileAtomic(pathname: string, value: string, mode = 0o60
fs.chmodSync(tempPath, mode);
fs.renameSync(tempPath, pathname);
}
export function describeUnknownError(err: unknown): string {
return formatErrorMessage(err);
}