refactor(runtime): share error normalization helper · openclaw/openclaw@5636c60
vincentkoc
·
2026-06-23
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -6,6 +6,7 @@ import type {
|
6 | 6 | ResponseInput, |
7 | 7 | ResponseStreamEvent, |
8 | 8 | } from "openai/resources/responses/responses.js"; |
| 9 | +import { toErrorObject } from "../../infra/errors.js"; |
9 | 10 | |
10 | 11 | // NEVER convert to top-level runtime imports - breaks browser/Vite builds |
11 | 12 | let os: typeof NodeOs | null = null; |
@@ -1325,7 +1326,7 @@ async function* parseWebSocket(
|
1325 | 1326 | } |
1326 | 1327 | |
1327 | 1328 | if (failed) { |
1328 | | -throw toLintErrorObject(failed, "Non-Error thrown"); |
| 1329 | +throw toErrorObject(failed, "Non-Error thrown"); |
1329 | 1330 | } |
1330 | 1331 | if (!sawCompletion) { |
1331 | 1332 | throw new Error("WebSocket stream closed before response.completed"); |
@@ -1639,17 +1640,3 @@ function buildWebSocketHeaders(
|
1639 | 1640 | headers.set("session_id", requestId); |
1640 | 1641 | return headers; |
1641 | 1642 | } |
1642 | | - |
1643 | | -function toLintErrorObject(value: unknown, fallbackMessage: string): Error { |
1644 | | -if (value instanceof Error) { |
1645 | | -return value; |
1646 | | -} |
1647 | | -if (typeof value === "string") { |
1648 | | -return new Error(value); |
1649 | | -} |
1650 | | -const error = new Error(fallbackMessage, { cause: value }); |
1651 | | -if ((typeof value === "object" && value !== null) || typeof value === "function") { |
1652 | | -Object.assign(error, value); |
1653 | | -} |
1654 | | -return error; |
1655 | | -} |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -6,6 +6,7 @@
|
6 | 6 | */ |
7 | 7 | |
8 | 8 | import type { Server } from "node:http"; |
| 9 | +import { toErrorObject } from "../../../infra/errors.js"; |
9 | 10 | import { |
10 | 11 | generateOAuthState, |
11 | 12 | generatePKCE, |
@@ -359,7 +360,7 @@ export async function loginAnthropic(options: {
|
359 | 360 | if (!code) { |
360 | 361 | await withOAuthLoginAbort(manualPromise, options.signal, server.cancelWait); |
361 | 362 | if (manualError) { |
362 | | -throw toLintErrorObject(manualError, "Non-Error thrown"); |
| 363 | +throw toErrorObject(manualError, "Non-Error thrown"); |
363 | 364 | } |
364 | 365 | if (manualInput) { |
365 | 366 | const parsed = parseOAuthAuthorizationInput(manualInput); |
@@ -462,17 +463,3 @@ export const anthropicOAuthProvider: OAuthProviderInterface = {
|
462 | 463 | return credentials.access; |
463 | 464 | }, |
464 | 465 | }; |
465 | | - |
466 | | -function toLintErrorObject(value: unknown, fallbackMessage: string): Error { |
467 | | -if (value instanceof Error) { |
468 | | -return value; |
469 | | -} |
470 | | -if (typeof value === "string") { |
471 | | -return new Error(value); |
472 | | -} |
473 | | -const error = new Error(fallbackMessage, { cause: value }); |
474 | | -if ((typeof value === "object" && value !== null) || typeof value === "function") { |
475 | | -Object.assign(error, value); |
476 | | -} |
477 | | -return error; |
478 | | -} |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -6,7 +6,7 @@ import { redactSensitiveUrlLikeString } from "@openclaw/net-policy/redact-sensit
|
6 | 6 | import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce"; |
7 | 7 | import { sanitizeForLog } from "../../packages/terminal-core/src/ansi.js"; |
8 | 8 | import { resolveArchiveKind } from "../infra/archive.js"; |
9 | | -import { formatErrorMessage } from "../infra/errors.js"; |
| 9 | +import { formatErrorMessage, toErrorObject } from "../infra/errors.js"; |
10 | 10 | import { pathExists } from "../infra/fs-safe.js"; |
11 | 11 | import { resolveOsHomeRelativePath } from "../infra/home-dir.js"; |
12 | 12 | import { tryReadJson } from "../infra/json-files.js"; |
@@ -792,7 +792,7 @@ async function readMarketplaceChunkWithTimeout(
|
792 | 792 | (err: unknown) => { |
793 | 793 | clear(); |
794 | 794 | if (!timedOut) { |
795 | | -reject(toLintErrorObject(err, "Non-Error rejection")); |
| 795 | +reject(toErrorObject(err, "Non-Error rejection")); |
796 | 796 | } |
797 | 797 | }, |
798 | 798 | ); |
@@ -1334,17 +1334,3 @@ export async function installPluginFromMarketplace(
|
1334 | 1334 | await loaded.marketplace.cleanup?.(); |
1335 | 1335 | } |
1336 | 1336 | } |
1337 | | - |
1338 | | -function toLintErrorObject(value: unknown, fallbackMessage: string): Error { |
1339 | | -if (value instanceof Error) { |
1340 | | -return value; |
1341 | | -} |
1342 | | -if (typeof value === "string") { |
1343 | | -return new Error(value); |
1344 | | -} |
1345 | | -const error = new Error(fallbackMessage, { cause: value }); |
1346 | | -if ((typeof value === "object" && value !== null) || typeof value === "function") { |
1347 | | -Object.assign(error, value); |
1348 | | -} |
1349 | | -return error; |
1350 | | -} |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -2,6 +2,7 @@
|
2 | 2 | import { appendFileSync } from "node:fs"; |
3 | 3 | import * as nodePty from "@lydell/node-pty"; |
4 | 4 | import type { PtyExitEvent, PtyHandle } from "@lydell/node-pty"; |
| 5 | +import { toErrorObject } from "../infra/errors.js"; |
5 | 6 | |
6 | 7 | // Shared PTY harness utilities for fake-backend and local TUI smoke tests. |
7 | 8 | type NodePtyRuntimeModule = typeof nodePty & { |
@@ -34,7 +35,7 @@ export function waitFor<T>(params: {
|
34 | 35 | try { |
35 | 36 | result = params.read(); |
36 | 37 | } catch (error) { |
37 | | -reject(toLintErrorObject(error, "Non-Error rejection")); |
| 38 | +reject(toErrorObject(error, "Non-Error rejection")); |
38 | 39 | return; |
39 | 40 | } |
40 | 41 | if (result !== null) { |
@@ -176,17 +177,3 @@ export function startPty(
|
176 | 177 | opts.activeRuns?.push(run); |
177 | 178 | return run; |
178 | 179 | } |
179 | | - |
180 | | -function toLintErrorObject(value: unknown, fallbackMessage: string): Error { |
181 | | -if (value instanceof Error) { |
182 | | -return value; |
183 | | -} |
184 | | -if (typeof value === "string") { |
185 | | -return new Error(value); |
186 | | -} |
187 | | -const error = new Error(fallbackMessage, { cause: value }); |
188 | | -if ((typeof value === "object" && value !== null) || typeof value === "function") { |
189 | | -Object.assign(error, value); |
190 | | -} |
191 | | -return error; |
192 | | -} |
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。