Skip to content
中文

getErrorInfo ​

CORE · function · Runtime value

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.

Import ​

ts
import { getErrorInfo } from '@jangts/agent-core';
js
import { getErrorInfo } from '@jangts/agent-core';

Other public entry points:@jangts/agent-core, @jangts/agent-core/types.

Definition ​

Call ​

ts
getErrorInfo(error: unknown): AgentErrorInfo

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.

ParameterTypePassingDescription
errorunknownRequired—

Returns: AgentErrorInfo.

Return value structure
FieldTypeRequiredDescription
codestringRequiredRead-only. Primary code: the error's own code, or a derived/fallback classification.
codesreadonly string[]RequiredRead-only. Every code observed while inspecting the error and its causes, primary code first.
issuesreadonly Readonly<Issue>[]RequiredRead-only. Structured issues found on the error; empty when the source reported none.
stageIdstring | undefinedOptionalRead-only. Execution stage that recorded the error, when the boundary annotated it.
isRetryableboolean | undefinedOptionalRead-only. Present only when the source stated retryability; absence means unknown.
causeunknownRequiredRead-only. Original thrown value, kept for identity and host-specific handling.

Examples ​

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); // false
js
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

Distinguish 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));

API reference, usage examples and developer guides.