Skip to content

Errors and warnings ​

Runtime problems are returned, never thrown: interpret(), resolve() and apply() always produce an InterpretResult. Only configuration mistakes throw PragmaConfigError, and they do so at construction time.

Every problem is a serializable PragmaIssue:

ts
interface PragmaIssue {
  code: ErrorCode; // stable, see below
  message: string; // English fallback
  messageKey: string; // for your own translations, e.g. "field.unknown"
  params?: Record<string, string | number | boolean | string[]>;
  path?: (string | number)[]; // where in the payload
  field?: string;
  retryable: boolean; // may retrying the same request succeed?
  details?: Record<string, unknown>; // e.g. suggestions, allowed operators
}

Issues never contain stack traces, upstream response bodies or secrets. Unknown internal errors become INTERNAL_ERROR with a generic message.

Error codes ​

Codes are part of the public API: they are never renamed or removed within a major version. New codes may be added, so handle unknown codes gracefully.

CodeTypical causeResult statusHTTP (server)
SCHEMA_ERRORinvalid schema (thrown at startup, or a bad client schema)—422
CONFIG_ERRORinvalid engine, handler or provider configuration (thrown)——
PARSE_ERRORempty instructionerror400
UNKNOWN_FIELDunknown or hidden fieldunsupported200
UNKNOWN_RESOURCE@orders.total on a customers tableunsupported200 / 404
INVALID_OPERATORe.g. contains on a numberunsupported200
INVALID_VALUEvalue can't be coerced to the field typeunsupported200
TYPE_MISMATCHreserved for adapters
AMBIGUOUS_QUERYreserved (ambiguity is normally a clarification result)
UNSUPPORTED_OPERATIONnot expressible (joins, aggregation, non-sortable field, …)unsupported200
CAPABILITY_UNSUPPORTEDe.g. page jump with cursor paginationunsupported200
TARGET_NOT_FOUNDremoving a filter or sort that isn't applied; no next cursorunsupported200
LIMIT_EXCEEDEDinstruction length, page size, conditions, nesting, sortsunsupported / error200 / 400 / 413
VALIDATION_ERRORmalformed payload or current stateerror422
UNSUPPORTED_PROTOCOL_VERSIONpayload from another major versionerror400
MODEL_ERRORprovider failure (network, 5xx, bad request)error502
MODEL_OUTPUT_INVALIDthe model's answer couldn't be understood or repairederror502
MODEL_UNAVAILABLEno model configured and the parser can't handle the instructionunsupported200
RATE_LIMITEDupstream or endpoint rate limiterror429 + Retry-After
TIMEOUTmodel deadline exceedederror504
ABORTEDcancelled by the callererror499
UNAUTHORIZEDauthorization hook denied the request (server) / provider rejected credentialserror401/403 / 502
TRANSPORT_ERRORbrowser couldn't reach or understand the Pragma servererror—
INTERNAL_ERRORbug; always has a request iderror500

Warnings ​

Warnings accompany ok results and never block them.

CodeMeaning
EMPTY_RANGEAND-ed conditions on one field can never overlap (age > 30 AND age < 20)
CONFLICTING_EQUALITYone field must equal two different values
EMPTY_INTERSECTIONAND-ed in/eq sets share no value
CONFLICTING_NULLa field must be both missing and have a value
BOUNDS_REORDEREDa reversed between range was swapped
DUPLICATE_REMOVEDidentical conditions or sorts were de-duplicated
CONDITIONS_MERGEDOR-ed equality on one field became a single in
VALUE_CLAMPEDpage size clamped (bestGuess policy)
ASSUMPTION_APPLIEDan ambiguity's default option was applied (bestGuess policy)
TIMEZONE_DEFAULTEDrelative dates resolved in UTC because no timezone was configured
MULTIPLE_TARGETS_AFFECTEDone removal removed several filters
PAGE_CLAMPED"previous page" on the first page
MODEL_UNAVAILABLEreserved for degraded responses

Pragma reports impossible queries; it never silently "fixes" them.

Thrown errors ​

PragmaError (base), PragmaConfigError, PragmaValidationError, PragmaModelError (status, retryAfterMs), PragmaTransportError (status) and PragmaTimeoutError. Use isPragmaError(value): it works across bundles and realms. error.toIssue() gives the serializable form.

Server responses ​

@avinash-baraiya/pragma-server answers completed interpretations (ok, needs_clarification, unsupported) with 200 and the InterpretResult. Every other outcome is an RFC 9457 application/problem+json body:

json
{
  "type": "https://github.com/Avinash-Baraiya/Pragma/blob/main/docs/errors.md#rate-limited",
  "title": "Too Many Requests",
  "status": 429,
  "code": "RATE_LIMITED",
  "detail": "Too many requests.",
  "requestId": "req_1x2y3z"
}

x-request-id is accepted (if well-formed) and always echoed.

Released under the MIT License.