mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-27 12:56:01 -06:00
refactor: consolidate remaining coercion helpers (#122020)
This commit is contained in:
committed by
GitHub
parent
24bbb416b5
commit
cad77fb39c
@@ -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
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user