getErrorInfo
CORE · function · 运行时值
Produce a frozen diagnostic view of any thrown value.
Inspection is guarded: an exotic error (revoked proxy, throwing getter, null prototype) degrades to UNKNOWN_ERROR instead of raising a second failure while handling the first.
导入
ts
import { getErrorInfo } from '@jangts/agent-core';js
import { getErrorInfo } from '@jangts/agent-core';其他公开入口:@jangts/agent-core、@jangts/agent-core/types。
定义
调用
ts
getErrorInfo(error: unknown): AgentErrorInfoProduce a frozen diagnostic view of any thrown value.
Inspection is guarded: an exotic error (revoked proxy, throwing getter, null prototype) degrades to UNKNOWN_ERROR instead of raising a second failure while handling the first.
| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
error | unknown | 必需 | — |
返回: AgentErrorInfo。
返回值结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
code | string | 必需 | 只读。Primary code: the error's own code, or a derived/fallback classification. |
codes | readonly string[] | 必需 | 只读。Every code observed while inspecting the error and its causes, primary code first. |
issues | readonly Readonly<Issue>[] | 必需 | 只读。Structured issues found on the error; empty when the source reported none. |
stageId | string | undefined | 可省略 | 只读。Execution stage that recorded the error, when the boundary annotated it. |
isRetryable | boolean | undefined | 可省略 | 只读。Present only when the source stated retryability; absence means unknown. |
cause | unknown | 必需 | 只读。Original thrown value, kept for identity and host-specific handling. |
使用示例
- 尝试预算与错误归属:将尝试次数、数据无效和流程合同错误分别表达,不把所有失败都转成成功正文。
只给两次业务尝试
入门 · Node.js
ts
import { AttemptBudget } from '@jangts/agent-core/engine';
const attempts = new AttemptBudget(2);
while (attempts.take()) console.log('attempt', attempts.used);
console.log(attempts.available); // falsejs
import { AttemptBudget } from '@jangts/agent-core/engine';
const attempts = new AttemptBudget(2);
while (attempts.take())
console.log('attempt', attempts.used);
console.log(attempts.available); // false明确额度不足与数据无效
配置 · Node.js
ts
import { BudgetError, ValidationError, getErrorInfo } from '@jangts/agent-core';
function requireAnswer(answer: string) {
if (!answer.trim()) throw new ValidationError([{ code: 'ANSWER_EMPTY', message: '回答不能为空' }]);
return answer;
}
try { requireAnswer(''); }
catch (error) { console.log(getErrorInfo(error)); }
const exhausted = new BudgetError('本次业务的尝试额度已用尽');
console.log(getErrorInfo(exhausted));js
import { BudgetError, ValidationError, getErrorInfo } from '@jangts/agent-core';
function requireAnswer(answer) {
if (!answer.trim())
throw new ValidationError([{ code: 'ANSWER_EMPTY', message: '回答不能为空' }]);
return answer;
}
try {
requireAnswer('');
}
catch (error) {
console.log(getErrorInfo(error));
}
const exhausted = new BudgetError('本次业务的尝试额度已用尽');
console.log(getErrorInfo(exhausted));