Skip to content

Commit b10fedb

Browse files
committed
refactor(acp): reuse shared error normalization
1 parent 008d101 commit b10fedb

3 files changed

Lines changed: 6 additions & 46 deletions

File tree

src/acp/control-plane/manager.core.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
} from "@openclaw/acp-core/runtime/types";
88
import type { OpenClawConfig } from "../../config/types.openclaw.js";
99
import { logVerbose } from "../../globals.js";
10+
import { toErrorObject } from "../../infra/errors.js";
1011
import { isAcpSessionKey } from "../../sessions/session-key-utils.js";
1112
import { AcpRuntimeError } from "../runtime/errors.js";
1213
import { runManagerCancelSession } from "./manager.cancel-session.js";
@@ -584,7 +585,7 @@ export class AcpSessionManager {
584585
}
585586
settled = true;
586587
cleanup();
587-
reject(toLintErrorObject(error, "Non-Error rejection"));
588+
reject(toErrorObject(error, "Non-Error rejection"));
588589
};
589590
const onAbort = () => {
590591
if (actorStarted) {
@@ -612,17 +613,3 @@ export class AcpSessionManager {
612613
throw new AcpRuntimeError("ACP_TURN_FAILED", "ACP operation aborted.");
613614
}
614615
}
615-
616-
function toLintErrorObject(value: unknown, fallbackMessage: string): Error {
617-
if (value instanceof Error) {
618-
return value;
619-
}
620-
if (typeof value === "string") {
621-
return new Error(value);
622-
}
623-
const error = new Error(fallbackMessage, { cause: value });
624-
if ((typeof value === "object" && value !== null) || typeof value === "function") {
625-
Object.assign(error, value);
626-
}
627-
return error;
628-
}

src/acp/control-plane/manager.runtime-resume-state.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { resolveSessionIdentityFromMeta } from "@openclaw/acp-core/runtime/sessi
33
import type { AcpRuntime } from "@openclaw/acp-core/runtime/types";
44
import type { OpenClawConfig } from "../../config/types.openclaw.js";
55
import { logVerbose } from "../../globals.js";
6-
import { formatErrorMessage } from "../../infra/errors.js";
6+
import { formatErrorMessage, toErrorObject } from "../../infra/errors.js";
77
import type { AcpRuntimeError } from "../runtime/errors.js";
88
import type { ManagerRuntimeHandleCache } from "./manager.runtime-handle-cache.js";
99
import type {
@@ -188,7 +188,7 @@ export async function tryPrepareFreshManagerRuntimeSession(params: {
188188
const backend = params.deps.getRuntimeBackend(configuredBackend || undefined);
189189
if (!backend) {
190190
if (params.missingBackendError) {
191-
throw toLintErrorObject(params.missingBackendError, "Non-Error thrown");
191+
throw toErrorObject(params.missingBackendError, "Non-Error thrown");
192192
}
193193
return;
194194
}
@@ -201,17 +201,3 @@ export async function tryPrepareFreshManagerRuntimeSession(params: {
201201
);
202202
}
203203
}
204-
205-
function toLintErrorObject(value: unknown, fallbackMessage: string): Error {
206-
if (value instanceof Error) {
207-
return value;
208-
}
209-
if (typeof value === "string") {
210-
return new Error(value);
211-
}
212-
const error = new Error(fallbackMessage, { cause: value });
213-
if ((typeof value === "object" && value !== null) || typeof value === "function") {
214-
Object.assign(error, value);
215-
}
216-
return error;
217-
}

src/acp/control-plane/manager.utils.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from "../../config/sessions/main-session.js";
88
import type { SessionAcpMeta } from "../../config/sessions/types.js";
99
import type { OpenClawConfig } from "../../config/types.openclaw.js";
10+
import { toErrorObject } from "../../infra/errors.js";
1011
import {
1112
normalizeAgentId,
1213
normalizeMainKey,
@@ -49,7 +50,7 @@ export function requireReadySessionMeta(resolution: AcpSessionResolution): Sessi
4950
if (resolution.kind === "ready") {
5051
return resolution.meta;
5152
}
52-
throw toLintErrorObject(resolveAcpSessionResolutionError(resolution), "Non-Error thrown");
53+
throw toErrorObject(resolveAcpSessionResolutionError(resolution), "Non-Error thrown");
5354
}
5455

5556
function normalizeSessionKey(sessionKey: string): string {
@@ -129,17 +130,3 @@ export function hasLegacyAcpIdentityProjection(meta: SessionAcpMeta): boolean {
129130
Object.hasOwn(raw, "sessionIdsProvisional")
130131
);
131132
}
132-
133-
function toLintErrorObject(value: unknown, fallbackMessage: string): Error {
134-
if (value instanceof Error) {
135-
return value;
136-
}
137-
if (typeof value === "string") {
138-
return new Error(value);
139-
}
140-
const error = new Error(fallbackMessage, { cause: value });
141-
if ((typeof value === "object" && value !== null) || typeof value === "function") {
142-
Object.assign(error, value);
143-
}
144-
return error;
145-
}

0 commit comments

Comments
 (0)