mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-27 12:56:01 -06:00
refactor(agents): reuse shared error normalization
This commit is contained in:
@@ -8,6 +8,7 @@ import { existsSync } from "node:fs";
|
||||
import { Container, Text, truncateToWidth } from "@earendil-works/pi-tui";
|
||||
import { resolveTimerTimeoutMs } from "@openclaw/normalization-core/number-coercion";
|
||||
import { Type } from "typebox";
|
||||
import { toErrorObject } from "../../../infra/errors.js";
|
||||
import { keyHint } from "../../modes/interactive/components/keybinding-hints.js";
|
||||
import { truncateToVisualLines } from "../../modes/interactive/components/visual-truncate.js";
|
||||
import { theme } from "../../modes/interactive/theme/theme.js";
|
||||
@@ -121,7 +122,7 @@ export function createLocalBashOperations(options?: { shellPath?: string }): Bas
|
||||
if (signal) {
|
||||
signal.removeEventListener("abort", onAbort);
|
||||
}
|
||||
reject(toLintErrorObject(err, "Non-Error rejection"));
|
||||
reject(toErrorObject(err, "Non-Error rejection"));
|
||||
});
|
||||
});
|
||||
},
|
||||
@@ -473,17 +474,3 @@ export function createBashTool(
|
||||
): AgentTool<typeof bashSchema> {
|
||||
return wrapToolDefinition(createBashToolDefinition(cwd, options));
|
||||
}
|
||||
|
||||
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 { existsSync, readdirSync, statSync } from "node:fs";
|
||||
import nodePath from "node:path";
|
||||
import { Text } from "@earendil-works/pi-tui";
|
||||
import { Type } from "typebox";
|
||||
import { toErrorObject } from "../../../infra/errors.js";
|
||||
import type { AgentTool } from "../../runtime/index.js";
|
||||
import type { ToolDefinition, ToolRenderResultOptions } from "../extensions/types.js";
|
||||
import { normalizePositiveLimit } from "./limits.js";
|
||||
@@ -216,7 +217,7 @@ export function createLsToolDefinition(
|
||||
});
|
||||
} catch (e: unknown) {
|
||||
signal?.removeEventListener("abort", onAbort);
|
||||
reject(toLintErrorObject(e, "Non-Error rejection"));
|
||||
reject(toErrorObject(e, "Non-Error rejection"));
|
||||
}
|
||||
})();
|
||||
});
|
||||
@@ -237,17 +238,3 @@ export function createLsToolDefinition(
|
||||
export function createLsTool(cwd: string, options?: LsToolOptions): AgentTool<typeof lsSchema> {
|
||||
return wrapToolDefinition(createLsToolDefinition(cwd, options));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import { access as fsAccess, readFile as fsReadFile } from "node:fs/promises";
|
||||
import { basename, dirname, isAbsolute, relative, resolve as resolvePath, sep } from "node:path";
|
||||
import { Text } from "@earendil-works/pi-tui";
|
||||
import { Type } from "typebox";
|
||||
import { toErrorObject } from "../../../infra/errors.js";
|
||||
import { decodeWindowsTextFileBuffer } from "../../../infra/windows-encoding.js";
|
||||
import type { ImageContent, Model, TextContent } from "../../../llm/types.js";
|
||||
import {
|
||||
@@ -409,7 +410,7 @@ export function createReadToolDefinition(
|
||||
} catch (error: unknown) {
|
||||
signal?.removeEventListener("abort", onAbort);
|
||||
if (!aborted) {
|
||||
reject(toLintErrorObject(error, "Non-Error rejection"));
|
||||
reject(toErrorObject(error, "Non-Error rejection"));
|
||||
}
|
||||
}
|
||||
})();
|
||||
@@ -451,17 +452,3 @@ export function createReadTool(
|
||||
): AgentTool<typeof readSchema> {
|
||||
return wrapToolDefinition(createReadToolDefinition(cwd, options));
|
||||
}
|
||||
|
||||
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