mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-27 21:07:01 -06:00
refactor(acp): reuse shared error normalization
This commit is contained in:
@@ -7,6 +7,7 @@ import type {
|
||||
} from "@openclaw/acp-core/runtime/types";
|
||||
import type { OpenClawConfig } from "../../config/types.openclaw.js";
|
||||
import { logVerbose } from "../../globals.js";
|
||||
import { toErrorObject } from "../../infra/errors.js";
|
||||
import { isAcpSessionKey } from "../../sessions/session-key-utils.js";
|
||||
import { AcpRuntimeError } from "../runtime/errors.js";
|
||||
import { runManagerCancelSession } from "./manager.cancel-session.js";
|
||||
@@ -584,7 +585,7 @@ export class AcpSessionManager {
|
||||
}
|
||||
settled = true;
|
||||
cleanup();
|
||||
reject(toLintErrorObject(error, "Non-Error rejection"));
|
||||
reject(toErrorObject(error, "Non-Error rejection"));
|
||||
};
|
||||
const onAbort = () => {
|
||||
if (actorStarted) {
|
||||
@@ -612,17 +613,3 @@ export class AcpSessionManager {
|
||||
throw new AcpRuntimeError("ACP_TURN_FAILED", "ACP operation aborted.");
|
||||
}
|
||||
}
|
||||
|
||||
function toLintErrorObject(value: unknown, fallbackMessage: string): Error {
|
||||
if (value instanceof Error) {
|
||||
return value;
|
||||
}
|
||||
if (typeof value === "string") {
|
||||
return new Error(value);
|
||||
}
|
||||
const error = new Error(fallbackMessage, { cause: value });
|
||||
if ((typeof value === "object" && value !== null) || typeof value === "function") {
|
||||
Object.assign(error, value);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { resolveSessionIdentityFromMeta } from "@openclaw/acp-core/runtime/sessi
|
||||
import type { AcpRuntime } from "@openclaw/acp-core/runtime/types";
|
||||
import type { OpenClawConfig } from "../../config/types.openclaw.js";
|
||||
import { logVerbose } from "../../globals.js";
|
||||
import { formatErrorMessage } from "../../infra/errors.js";
|
||||
import { formatErrorMessage, toErrorObject } from "../../infra/errors.js";
|
||||
import type { AcpRuntimeError } from "../runtime/errors.js";
|
||||
import type { ManagerRuntimeHandleCache } from "./manager.runtime-handle-cache.js";
|
||||
import type {
|
||||
@@ -188,7 +188,7 @@ export async function tryPrepareFreshManagerRuntimeSession(params: {
|
||||
const backend = params.deps.getRuntimeBackend(configuredBackend || undefined);
|
||||
if (!backend) {
|
||||
if (params.missingBackendError) {
|
||||
throw toLintErrorObject(params.missingBackendError, "Non-Error thrown");
|
||||
throw toErrorObject(params.missingBackendError, "Non-Error thrown");
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -201,17 +201,3 @@ export async function tryPrepareFreshManagerRuntimeSession(params: {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function toLintErrorObject(value: unknown, fallbackMessage: string): Error {
|
||||
if (value instanceof Error) {
|
||||
return value;
|
||||
}
|
||||
if (typeof value === "string") {
|
||||
return new Error(value);
|
||||
}
|
||||
const error = new Error(fallbackMessage, { cause: value });
|
||||
if ((typeof value === "object" && value !== null) || typeof value === "function") {
|
||||
Object.assign(error, value);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
} from "../../config/sessions/main-session.js";
|
||||
import type { SessionAcpMeta } from "../../config/sessions/types.js";
|
||||
import type { OpenClawConfig } from "../../config/types.openclaw.js";
|
||||
import { toErrorObject } from "../../infra/errors.js";
|
||||
import {
|
||||
normalizeAgentId,
|
||||
normalizeMainKey,
|
||||
@@ -49,7 +50,7 @@ export function requireReadySessionMeta(resolution: AcpSessionResolution): Sessi
|
||||
if (resolution.kind === "ready") {
|
||||
return resolution.meta;
|
||||
}
|
||||
throw toLintErrorObject(resolveAcpSessionResolutionError(resolution), "Non-Error thrown");
|
||||
throw toErrorObject(resolveAcpSessionResolutionError(resolution), "Non-Error thrown");
|
||||
}
|
||||
|
||||
function normalizeSessionKey(sessionKey: string): string {
|
||||
@@ -129,17 +130,3 @@ export function hasLegacyAcpIdentityProjection(meta: SessionAcpMeta): boolean {
|
||||
Object.hasOwn(raw, "sessionIdsProvisional")
|
||||
);
|
||||
}
|
||||
|
||||
function toLintErrorObject(value: unknown, fallbackMessage: string): Error {
|
||||
if (value instanceof Error) {
|
||||
return value;
|
||||
}
|
||||
if (typeof value === "string") {
|
||||
return new Error(value);
|
||||
}
|
||||
const error = new Error(fallbackMessage, { cause: value });
|
||||
if ((typeof value === "object" && value !== null) || typeof value === "function") {
|
||||
Object.assign(error, value);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user