refactor(acp): reuse shared error normalization · openclaw/openclaw@b10fedb
vincentkoc
·
2026-06-22
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -7,6 +7,7 @@ import type {
|
7 | 7 | } from "@openclaw/acp-core/runtime/types"; |
8 | 8 | import type { OpenClawConfig } from "../../config/types.openclaw.js"; |
9 | 9 | import { logVerbose } from "../../globals.js"; |
| 10 | +import { toErrorObject } from "../../infra/errors.js"; |
10 | 11 | import { isAcpSessionKey } from "../../sessions/session-key-utils.js"; |
11 | 12 | import { AcpRuntimeError } from "../runtime/errors.js"; |
12 | 13 | import { runManagerCancelSession } from "./manager.cancel-session.js"; |
@@ -584,7 +585,7 @@ export class AcpSessionManager {
|
584 | 585 | } |
585 | 586 | settled = true; |
586 | 587 | cleanup(); |
587 | | -reject(toLintErrorObject(error, "Non-Error rejection")); |
| 588 | +reject(toErrorObject(error, "Non-Error rejection")); |
588 | 589 | }; |
589 | 590 | const onAbort = () => { |
590 | 591 | if (actorStarted) { |
@@ -612,17 +613,3 @@ export class AcpSessionManager {
|
612 | 613 | throw new AcpRuntimeError("ACP_TURN_FAILED", "ACP operation aborted."); |
613 | 614 | } |
614 | 615 | } |
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 | | -} |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -3,7 +3,7 @@ import { resolveSessionIdentityFromMeta } from "@openclaw/acp-core/runtime/sessi
|
3 | 3 | import type { AcpRuntime } from "@openclaw/acp-core/runtime/types"; |
4 | 4 | import type { OpenClawConfig } from "../../config/types.openclaw.js"; |
5 | 5 | import { logVerbose } from "../../globals.js"; |
6 | | -import { formatErrorMessage } from "../../infra/errors.js"; |
| 6 | +import { formatErrorMessage, toErrorObject } from "../../infra/errors.js"; |
7 | 7 | import type { AcpRuntimeError } from "../runtime/errors.js"; |
8 | 8 | import type { ManagerRuntimeHandleCache } from "./manager.runtime-handle-cache.js"; |
9 | 9 | import type { |
@@ -188,7 +188,7 @@ export async function tryPrepareFreshManagerRuntimeSession(params: {
|
188 | 188 | const backend = params.deps.getRuntimeBackend(configuredBackend || undefined); |
189 | 189 | if (!backend) { |
190 | 190 | if (params.missingBackendError) { |
191 | | -throw toLintErrorObject(params.missingBackendError, "Non-Error thrown"); |
| 191 | +throw toErrorObject(params.missingBackendError, "Non-Error thrown"); |
192 | 192 | } |
193 | 193 | return; |
194 | 194 | } |
@@ -201,17 +201,3 @@ export async function tryPrepareFreshManagerRuntimeSession(params: {
|
201 | 201 | ); |
202 | 202 | } |
203 | 203 | } |
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 | | -} |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -7,6 +7,7 @@ import {
|
7 | 7 | } from "../../config/sessions/main-session.js"; |
8 | 8 | import type { SessionAcpMeta } from "../../config/sessions/types.js"; |
9 | 9 | import type { OpenClawConfig } from "../../config/types.openclaw.js"; |
| 10 | +import { toErrorObject } from "../../infra/errors.js"; |
10 | 11 | import { |
11 | 12 | normalizeAgentId, |
12 | 13 | normalizeMainKey, |
@@ -49,7 +50,7 @@ export function requireReadySessionMeta(resolution: AcpSessionResolution): Sessi
|
49 | 50 | if (resolution.kind === "ready") { |
50 | 51 | return resolution.meta; |
51 | 52 | } |
52 | | -throw toLintErrorObject(resolveAcpSessionResolutionError(resolution), "Non-Error thrown"); |
| 53 | +throw toErrorObject(resolveAcpSessionResolutionError(resolution), "Non-Error thrown"); |
53 | 54 | } |
54 | 55 | |
55 | 56 | function normalizeSessionKey(sessionKey: string): string { |
@@ -129,17 +130,3 @@ export function hasLegacyAcpIdentityProjection(meta: SessionAcpMeta): boolean {
|
129 | 130 | Object.hasOwn(raw, "sessionIdsProvisional") |
130 | 131 | ); |
131 | 132 | } |
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 | | -} |
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。