Errors
Part of TA-Lib's specification, a reference for AI-agent-driven integration.
The rules for what a rejected call reports, in C's spelling. Error handling written against one language maps onto the others (rE2). How each code reaches a Rust, Java, C# or TypeScript caller is on the hub.
The caller must
- Branch on the code, never on a message. Java's, C#'s and TypeScript's exceptions carry a message for people; its text is not specified.
- Fix one fault at a time. When a call breaks several conditions, which one it reports (rE1) is not specified.
- In C, ignore the range after a failure.
*outBegIdxand*outNBElementare then unspecified. A handle out-parameter: ownership. - In C, test internal errors as a range, never
== TA_INTERNAL_ERROR(rB8). - Stop after an allocation failure (rE3).
Return codes
The codes a batch, lookback or stream call can return:
| Code | TA_RetCode | Returned by |
|---|---|---|
| 0 | TA_SUCCESS | Every call that succeeds. |
| 2 | TA_BAD_PARAM | Most batch, opening and advancing conditions; a failed lookback, display shift or settings call, in a language where it reports a code (failures). |
| 3 | TA_ALLOC_ERR | rB7. |
| 12 | TA_OUT_OF_RANGE_START_INDEX | rB1. |
| 13 | TA_OUT_OF_RANGE_END_INDEX | rB2, rS2, rU4. |
| 17 | TA_INSUFFICIENT_HISTORY | Stream openers only (rS7). |
| 5000 to 5999 | TA_INTERNAL_ERROR + id | rB8. |
The Abstract API returns codes of its own: Abstract API and Metadata. The remaining members of TA_RetCode, declared in ta_defs.h, are returned by nothing.
General rules
rE1 A rejected call reports exactly one code (in Java, C# and TypeScript, one exception) and stops.
rE2 A call that breaks one condition of the batch or stream tables gets that condition's code from every language that can express and detect it.
rE3 A rejected call writes no output buffer. Nothing is promised after rB7 or rB8.
Batch conditions
| Rule | Condition | Code | Not expressible in |
|---|---|---|---|
| rB1 | startIdx is below 0 or above TA_INDEX_MAX. | TA_OUT_OF_RANGE_START_INDEX | Rust, below 0 (usize) |
| rB2 | endIdx is below 0, above TA_INDEX_MAX, or below startIdx. | TA_OUT_OF_RANGE_END_INDEX | Rust, below 0 |
| rB3 | rP2 rejects an optional parameter value or a combination of values. | TA_BAD_PARAM | none |
| rB4 | A required argument is absent: an input, an output, or in C a range out-parameter. TypeScript Caveat: rJ3. | TA_BAD_PARAM | none |
| rB5 | A buffer is too short: an input does not reach endIdx (input length), or an output cannot hold the count the call produces (output size). | TA_BAD_PARAM | none; C cannot detect it |
| rB6 | Two outputs are the same buffer. | TA_BAD_PARAM | Rust (safe code) |
| rB7 | A memory allocation failed. | TA_ALLOC_ERR (C only) | none |
| rB8 | The library found an inconsistency in its own state. | TA_INTERNAL_ERROR + id | none |
| rB9 | An index or an integer optional parameter is not a 32-bit integer (a fraction, NaN, ±Inf, or a value outside the int range), or a real optional parameter is not a number (a string, null or a boolean); undefined selects the default (rP1, rP2). | TA_BAD_PARAM | C, Rust, Java, C# |
rB4. An input or output is absent when it is NULL in C, null or an empty array in Java, an empty slice in Rust, an empty span in C# (a null array becomes one), and null, undefined or an empty array in TypeScript (TypeScript Caveat: rJ3). An absent one is rejected even when the range produces no values (rW2).
rB7. Rust, Java, C# and TypeScript allocate through their runtime.
rB8. Report it as a TA-Lib bug, with the number in C. C's TA_SetRetCodeInfo names every value from 5000 to 5999 TA_INTERNAL_ERROR, and a value that is not a TA_RetCode member TA_UNKNOWN_ERR. Rust, Java, C# and TypeScript report TA_INTERNAL_ERROR without an id.