AgentErrorInfo
CORE · interface · Type contract
Stable error metadata for App diagnostics. Unknown retryability is deliberately omitted.
Import
ts
import type { AgentErrorInfo } from '@jangts/agent-core/errors';js
/** @typedef {import('@jangts/agent-core/errors').AgentErrorInfo} AgentErrorInfo */Other public entry points:@jangts/agent-core, @jangts/agent-core/types, @jangts/agent-core/structs, @jangts/agent-core/errors.
Definition
ts
interface AgentErrorInfoField structure
| Field | Type | Required | Description |
|---|---|---|---|
code | string | Required | Read-only. Primary code: the error's own code, or a derived/fallback classification. |
codes | readonly string[] | Required | Read-only. Every code observed while inspecting the error and its causes, primary code first. |
issues | readonly Readonly<Issue>[] | Required | Read-only. Structured issues found on the error; empty when the source reported none. |
stageId | string | undefined | Optional | Read-only. Execution stage that recorded the error, when the boundary annotated it. |
isRetryable | boolean | undefined | Optional | Read-only. Present only when the source stated retryability; absence means unknown. |
cause | unknown | Required | Read-only. Original thrown value, kept for identity and host-specific handling. |
Examples
- Attempt budgets and error ownership: Express used attempts, invalid data, and workflow contract errors separately instead of turning every failure into successful prose.
Allow only two business attempts
Beginner · 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); // falseDistinguish an exhausted quota from invalid data
Configuration · 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));