refactor: consolidate remaining coercion helpers (#122020)

This commit is contained in:
Peter Steinberger
2026-08-11 10:22:01 -07:00
committed by GitHub
parent 24bbb416b5
commit cad77fb39c
234 changed files with 1210 additions and 1572 deletions
+1 -7
View File
@@ -1,4 +1,5 @@
// Device pairing runtime commands for gateway and loopback-local fallback operations.
import { coerceErrorMessage as normalizeErrorMessage } from "@openclaw/normalization-core/error-coercion";
import {
normalizeLowercaseStringOrEmpty,
normalizeOptionalString,
@@ -275,13 +276,6 @@ async function findQueryPendingNodeApprovalNotices(
);
}
function normalizeErrorMessage(error: unknown): string {
if (error instanceof Error) {
return error.message;
}
return String(error);
}
function isDevicePairingApprovalDenied(error: unknown): boolean {
return normalizeLowercaseStringOrEmpty(normalizeErrorMessage(error)).includes(
"device pairing approval denied",
+1 -7
View File
@@ -1,6 +1,7 @@
// Gateway logs CLI with RPC tailing, local file fallback, and systemd journal fallback.
import { setTimeout as delay } from "node:timers/promises";
import { redactSensitiveUrlLikeString } from "@openclaw/net-policy/redact-sensitive-url";
import { coerceErrorMessage as normalizeErrorMessage } from "@openclaw/normalization-core/error-coercion";
import { resolveIntegerOption } from "@openclaw/normalization-core/number-coercion";
import { normalizeLowercaseStringOrEmpty } from "@openclaw/normalization-core/string-coerce";
import type { Command } from "commander";
@@ -204,13 +205,6 @@ async function fetchLogs(
}
}
function normalizeErrorMessage(error: unknown): string {
if (error instanceof Error) {
return error.message;
}
return String(error);
}
function normalizeError(error: unknown): Error {
return error instanceof Error ? error : new Error(String(error));
}
+3 -2
View File
@@ -273,11 +273,12 @@ vi.mock("../process/exec.js", () => ({
vi.mock("../utils.js", async (importOriginal) => {
const actual = await importOriginal<typeof import("../utils.js")>();
const isMockRecord = (value: unknown) =>
typeof value === "object" && value !== null && !Array.isArray(value);
return {
...actual,
displayString: (input: string) => input,
isRecord: (value: unknown) =>
typeof value === "object" && value !== null && !Array.isArray(value),
isRecord: isMockRecord,
pathExists: (...args: unknown[]) => pathExists(...args),
resolveConfigDir: () => "/tmp/openclaw-config",
sleep: vi.fn(async () => undefined),