C API
Errors
Interpret stable C status values and public diagnostics fail-closed.Declarations from <maelys/datalog.h> and its optional C11 builders <maelys/datalog_builders.h>. For explanations and complete examples, see the Errors guide.
The examples use failed_diagnostic and check_status supplied by the page reference context.
Enum: status_t
#include <maelys/datalog.h>
Typedef
typedef enum {
MAELYS_DATALOG_STATUS_OK = 0,
MAELYS_DATALOG_STATUS_INVALID_ARGUMENT = -1,
MAELYS_DATALOG_STATUS_INVALID_FIELD = -2,
MAELYS_DATALOG_STATUS_NOT_FOUND = -3,
MAELYS_DATALOG_STATUS_NOT_IMPLEMENTED = -4,
MAELYS_DATALOG_STATUS_UNSUPPORTED = -5,
MAELYS_DATALOG_STATUS_TIMEOUT = -6,
MAELYS_DATALOG_STATUS_IO = -7,
MAELYS_DATALOG_STATUS_INTERNAL = -8,
MAELYS_DATALOG_STATUS_UNAUTHORIZED = -9,
MAELYS_DATALOG_STATUS_FORBIDDEN = -10,
MAELYS_DATALOG_STATUS_RATE_LIMITED = -11,
MAELYS_DATALOG_STATUS_PAYLOAD_TOO_LARGE = -12,
MAELYS_DATALOG_STATUS_INVALID_STATE = -13,
MAELYS_DATALOG_STATUS_STORAGE_TOO_SMALL = -14
} maelys_datalog_status_t;Functions
status_name()
#include <maelys/datalog.h>
const char *
maelys_datalog_status_name(
maelys_datalog_status_t status
);const char *
Returns a readable status name for diagnostics; do not infer success from the text alone.
maelys_datalog_status_t status = maelys_datalog_limit_get(
MAELYS_DATALOG_LIMIT_MAX_ARITY, NULL);
if (status != MAELYS_DATALOG_STATUS_INVALID_ARGUMENT) return EXIT_FAILURE;
printf("status: %s\n", maelys_datalog_status_name(status));status: invalid_argument
Struct: diagnostic_t
#include <maelys/datalog.h>
Typedef
typedef struct {
size_t struct_size;
uint32_t abi_version;
maelys_datalog_diagnostic_source_t source;
maelys_datalog_status_t status;
maelys_datalog_diag_code_t code;
uint64_t present;
size_t line, column;
char phase[32], message[256], hint[256];
char file[256], predicate[96];
size_t arity, observed_count, limit, depth, depth_limit, rule_id;
unsigned comparison_result, expected_kind, lhs_kind, rhs_kind, comparison_op;
/* limit is the effective bound (possibly a smaller session reservation),
* while limit_get reports the library ceiling, or UNSUPPORTED for a
* dimension whose bound is session-specific. */
maelys_datalog_limit_t limit_kind; /* 0 when the producer cannot identify the budget. */
size_t term_index, expected_arity, observed_arity;
char token[96], field[96], domain[96];
} maelys_datalog_diagnostic_t;Creation
diagnostic_init()
#include <maelys/datalog.h>
maelys_datalog_status_t
maelys_datalog_diagnostic_init(
void *storage,
size_t storage_bytes
);Written on success.
maelys_datalog_status_t — OK on success.
Initializes the known ABI 1 object. Rejects storage that is too small before writing a diagnostic payload.
maelys_datalog_diagnostic_t diagnostic;
maelys_datalog_status_t status = maelys_datalog_diagnostic_init(
&diagnostic, sizeof(diagnostic));
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);
printf("diagnostic.status: %s\n", maelys_datalog_status_name(diagnostic.status));
printf("ABI version: %u\n", diagnostic.abi_version);status: ok diagnostic.status: ok ABI version: 1
DIAGNOSTIC_INIT
#include <maelys/datalog.h>
MAELYS_DATALOG_DIAGNOSTIC_INITConstructs an initialized diagnostic value.
Calls maelys_datalog_diagnostic_initializer(). Returns an initialized maelys_datalog_diagnostic_t value.
| Field | Initial value | Meaning |
|---|---|---|
struct_size | sizeof(d) | Size of the caller-provided object in bytes; required by diagnostic ABI 1.set automatically |
abi_version | MAELYS_DATALOG_DIAGNOSTIC_ABI_VERSION | Set to MAELYS_DATALOG_DIAGNOSTIC_ABI_VERSION (1).set automatically |
source | 0 | LOAD, SOLVE or NONE; NONE means no detail was supplied. |
status | 0 | Status associated with this populated diagnostic. |
code | 0 | Typed reason; use maelys_datalog_diag_code_name() for its stable name. |
present | 0 | Bitmask selecting the independent detail sections that are valid. |
line | 0 | Source line when LOCATION is present. |
column | 0 | Source column when LOCATION is present. |
phase | {0} | Bounded producer phase text. |
message | {0} | Bounded human-readable message, not a machine-readable code. |
hint | {0} | Bounded optional corrective guidance. |
file | {0} | Bounded source path when LOCATION is present. |
predicate | {0} | Predicate name when PREDICATE is present. |
arity | 0 | Predicate arity when PREDICATE is present. |
observed_count | 0 | Attempted count for a CAPACITY failure. |
limit | 0 | Capacity bound, or inclusive numeric aggregate bound when AGGREGATE is present. |
depth | 0 | Observed depth when DEPTH is present. |
depth_limit | 0 | Allowed depth when DEPTH is present. |
rule_id | 0 | Rule identifier when RULE is present. |
comparison_result | 0 | Comparison outcome when COMPARISON is present. |
expected_kind | 0 | Expected comparison kind when COMPARISON is present. |
lhs_kind | 0 | Left-hand IR kind; also the offending aggregate value kind. |
rhs_kind | 0 | Right-hand IR kind when COMPARISON is present. |
comparison_op | 0 | IR comparison operator when COMPARISON is present. |
limit_kind | 0 | Public capacity identifier; zero when no budget identity is available. |
term_index | 0 | Zero-based term or aggregate projection index when its section is present. |
expected_arity | 0 | Required arity when ARITY is present. |
observed_arity | 0 | Supplied arity when ARITY is present. |
token | {0} | Bounded offending token or aggregate value text. |
field | {0} | Bounded field name; min, max or sum for aggregate rejection. |
domain | {0} | Bounded domain name when CONTEXT is present. |
Expansion
maelys_datalog_diagnostic_initializer()maelys_datalog_diagnostic_t diagnostic = MAELYS_DATALOG_DIAGNOSTIC_INIT;
printf("diagnostic.status: %s\n", maelys_datalog_status_name(diagnostic.status));
printf("present: 0x%llx\n", (unsigned long long)diagnostic.present);diagnostic.status: ok present: 0x0
diagnostic_initializer()
#include <maelys/datalog.h>
static inline maelys_datalog_diagnostic_t
maelys_datalog_diagnostic_initializer(
void
);Returns a zeroed diagnostic with struct_size and abi_version set for diagnostic ABI 1. MAELYS_DATALOG_DIAGNOSTIC_INIT is the equivalent initializer macro.
maelys_datalog_diagnostic_t diagnostic = maelys_datalog_diagnostic_initializer();
printf("diagnostic.status: %s\n", maelys_datalog_status_name(diagnostic.status));
printf("present: 0x%llx\n", (unsigned long long)diagnostic.present);diagnostic.status: ok present: 0x0
Functions
diagnostic_clear()
#include <maelys/datalog.h>
maelys_datalog_status_t
maelys_datalog_diagnostic_clear(
maelys_datalog_diagnostic_t *diagnostic
);maelys_datalog_status_t — OK on success.
Resets the known fields while preserving struct_size and abi_version. This is not secure erasure.
maelys_datalog_diagnostic_t diagnostic = failed_diagnostic();
printf("diagnostic.status before: %s\n", maelys_datalog_status_name(diagnostic.status));
printf("diagnostic.code before: %s\n", maelys_datalog_diag_code_name(diagnostic.code));
maelys_datalog_status_t status = maelys_datalog_diagnostic_clear(&diagnostic);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);
printf("diagnostic.status after: %s\n", maelys_datalog_status_name(diagnostic.status));
printf("diagnostic.code after: %s\n", maelys_datalog_diag_code_name(diagnostic.code));
printf("diagnostic.present after: 0x%llx\n", (unsigned long long)diagnostic.present);diagnostic.status before: unsupported diagnostic.code before: manifest_unknown_domain status: ok diagnostic.status after: ok diagnostic.code after: none diagnostic.present after: 0x0
Constants
| Name | Value | Meaning |
|---|---|---|
DIAGNOSTIC_Since v0.10.0 | 0x100 | Aggregate field, offending value text and kind, projection index and inclusive numeric bound are populated. |
DIAGNOSTIC_Since v0.10.0 | 0x20 | Expected and observed arity are populated. |
DIAGNOSTIC_Since v0.10.0 | 0x4 | Attempted count, capacity bound and budget identity are populated. |
DIAGNOSTIC_Since v0.10.0 | 0x10 | Comparison outcome, operand kinds and operator are populated. |
DIAGNOSTIC_Since v0.10.0 | 0x80 | Domain and producer context are populated. |
DIAGNOSTIC_Since v0.10.0 | 0x8 | Observed and permitted depth are populated. |
DIAGNOSTIC_Since v0.10.0 | 0x1 | Source file, line and column are populated. |
DIAGNOSTIC_Since v0.10.0 | 0x2 | Predicate name and arity are populated. |
DIAGNOSTIC_Since v0.10.0 | 0x40 | Rule identifier is populated. |
Versioning
Initialize with the DIAGNOSTIC_INIT macro; these values identify the structure version and are not set by hand.
| Name | Value | Meaning |
|---|---|---|
DIAGNOSTIC_Since v0.10.0 | 1 | ABI version required when initializing this diagnostic record. |
| Used by | diagnostic_t — code |
|---|
Enum: diag_code_t
#include <maelys/datalog.h>
Typedef
typedef enum {
MAELYS_DATALOG_DIAG_NONE = 0,
MAELYS_DATALOG_DIAG_MANIFEST_INVALID_JSON,
MAELYS_DATALOG_DIAG_MANIFEST_INVALID_FIELD,
MAELYS_DATALOG_DIAG_MANIFEST_UNKNOWN_FIELD,
MAELYS_DATALOG_DIAG_MANIFEST_UNKNOWN_DOMAIN,
MAELYS_DATALOG_DIAG_MANIFEST_SHA_MISMATCH,
MAELYS_DATALOG_DIAG_MANIFEST_POLICY_NOT_FOUND,
MAELYS_DATALOG_DIAG_MANIFEST_TEST_ONLY_REJECTED,
MAELYS_DATALOG_DIAG_LEXER_INVALID_TOKEN,
MAELYS_DATALOG_DIAG_LEXER_UNSUPPORTED_CONSTRUCT,
MAELYS_DATALOG_DIAG_LEXER_INVALID_UTF8,
MAELYS_DATALOG_DIAG_LEXER_STRING_TOO_LONG,
MAELYS_DATALOG_DIAG_PARSER_EXPECTED_PREDICATE,
MAELYS_DATALOG_DIAG_PARSER_UNKNOWN_PREDICATE,
MAELYS_DATALOG_DIAG_PARSER_ARITY_MISMATCH,
MAELYS_DATALOG_DIAG_PARSER_UNKNOWN_ATOM,
MAELYS_DATALOG_DIAG_PARSER_RULE_HEAD_EDB_FORBIDDEN,
MAELYS_DATALOG_DIAG_PARSER_RULE_BODY_LITERAL_OVERFLOW,
MAELYS_DATALOG_DIAG_PARSER_UNSAFE_VARIABLE,
MAELYS_DATALOG_DIAG_PARSER_INVALID_COMPARISON,
MAELYS_DATALOG_DIAG_PARSER_INVALID_FILTER,
MAELYS_DATALOG_DIAG_PARSER_EXPECTED_DOT,
MAELYS_DATALOG_DIAG_PARSER_EXPECTED_NECK,
MAELYS_DATALOG_DIAG_PARSER_FACT_USES_NON_BASE_PREDICATE,
MAELYS_DATALOG_DIAG_PARSER_ANONYMOUS_VARIABLE_IN_HEAD,
/* Historical code name: also covers arithmetic expressions and not().
* The message identifies the rejected use of the anonymous variable. */
MAELYS_DATALOG_DIAG_PARSER_ANONYMOUS_VARIABLE_IN_COMPARISON,
MAELYS_DATALOG_DIAG_PARSER_ANONYMOUS_VARIABLE_IN_FACT,
MAELYS_DATALOG_DIAG_PARSER_TOO_MANY_VARIABLES,
/* Cycle, or finite stratum exhaustion (CAPACITY MAX_STRATA + DEPTH). */
MAELYS_DATALOG_DIAG_POLICY_NOT_STRATIFIABLE,
MAELYS_DATALOG_DIAG_RUNTIME_INVALID_COMPARISON,
MAELYS_DATALOG_DIAG_RUNTIME_INVALID_FILTER,
MAELYS_DATALOG_DIAG_REGISTRY_CONFLICT,
MAELYS_DATALOG_DIAG_REGISTRY_MUTATION_AFTER_FREEZE,
MAELYS_DATALOG_DIAG_MALFORMED_PROGRAM,
MAELYS_DATALOG_DIAG_OPERATION_REJECTED = 256,
MAELYS_DATALOG_DIAG_SOLVE_MAX_DEPTH = 513,
MAELYS_DATALOG_DIAG_SOLVE_IDB_OVERFLOW,
/* Includes arithmetic overflow; COMPARISON identifies operator/kinds.
* Arithmetic overflow is not CAPACITY exhaustion. */
MAELYS_DATALOG_DIAG_SOLVE_COMPARISON_TYPE_ERROR,
MAELYS_DATALOG_DIAG_SOLVE_FILTER_ERROR,
MAELYS_DATALOG_DIAG_SOLVE_MALFORMED_FACT,
MAELYS_DATALOG_DIAG_SOLVE_MALFORMED_EDB,
MAELYS_DATALOG_DIAG_SOLVE_INVALID_STATE,
MAELYS_DATALOG_DIAG_SOLVE_INVALID_ARGUMENT,
MAELYS_DATALOG_DIAG_SOLVE_INTERNAL_ERROR,
MAELYS_DATALOG_DIAG_SOLVE_AGGREGATE_DOMAIN_ERROR,
MAELYS_DATALOG_DIAG_SOLVE_SUM_OVERFLOW
} maelys_datalog_diag_code_t;Functions
diag_code_name()
#include <maelys/datalog.h>
const char *
maelys_datalog_diag_code_name(
maelys_datalog_diag_code_t code
);const char *
Returns a stable reason name suitable for diagnostics; the status remains the call outcome.
maelys_datalog_diagnostic_t diagnostic = failed_diagnostic();
printf("code name: %s\n", maelys_datalog_diag_code_name(diagnostic.code));code name: manifest_unknown_domain
Enum: diagnostic_source_t
#include <maelys/datalog.h>
Typedef
typedef enum {
MAELYS_DATALOG_DIAGNOSTIC_NONE = 0,
MAELYS_DATALOG_DIAGNOSTIC_LOAD = 1,
MAELYS_DATALOG_DIAGNOSTIC_SOLVE = 2
} maelys_datalog_diagnostic_source_t;| Used by | diagnostic_t — source |
|---|
| Used by | diagnostic_t — limit_kind |
|---|
Enum: limit_t
#include <maelys/datalog.h>
Typedef
typedef enum {
MAELYS_DATALOG_LIMIT_MAX_SYMBOLS = 1,
MAELYS_DATALOG_LIMIT_STRING_POOL_BYTES,
MAELYS_DATALOG_LIMIT_MAX_PREDICATES,
MAELYS_DATALOG_LIMIT_MAX_RULES,
MAELYS_DATALOG_LIMIT_MAX_ARITY,
MAELYS_DATALOG_LIMIT_MAX_BODY_LITERALS,
MAELYS_DATALOG_LIMIT_MAX_DEPTH,
MAELYS_DATALOG_LIMIT_MAX_EDB_FACTS,
MAELYS_DATALOG_LIMIT_MAX_IDB_FACTS,
MAELYS_DATALOG_LIMIT_MAX_FACTS_PER_PRED,
MAELYS_DATALOG_LIMIT_MAX_STRING_BYTES,
MAELYS_DATALOG_LIMIT_INPUT_EDB_TEXT_BYTES,
MAELYS_DATALOG_LIMIT_MAX_POLICY_ATOMS,
MAELYS_DATALOG_LIMIT_MAX_POLICY_ATOM_BYTES,
MAELYS_DATALOG_LIMIT_MAX_RULE_VARIABLES,
MAELYS_DATALOG_LIMIT_MAX_ARITH_EXPR_NODES,
MAELYS_DATALOG_LIMIT_MAX_ARITH_EXPR_DEPTH,
MAELYS_DATALOG_LIMIT_MAX_FILTER_PATTERN_BYTES,
MAELYS_DATALOG_LIMIT_MAX_FILTER_PROGRAMS,
MAELYS_DATALOG_LIMIT_FILTER_PATTERN_POOL_BYTES,
MAELYS_DATALOG_LIMIT_MAX_FILTER_EVALUATIONS,
MAELYS_DATALOG_LIMIT_MAX_FILTER_COST_UNITS,
MAELYS_DATALOG_LIMIT_SESSION_ARENA_BYTES,
MAELYS_DATALOG_LIMIT_EXECUTION_BYTES,
MAELYS_DATALOG_LIMIT_MAX_RULE_FACTS,
MAELYS_DATALOG_LIMIT_MAX_STRATA
} maelys_datalog_limit_t;Functions
limit_get()
#include <maelys/datalog.h>
maelys_datalog_status_t
maelys_datalog_limit_get(
maelys_datalog_limit_t limit,
size_t *out_value
);Written on success.
maelys_datalog_status_t — OK on success.
Returns OK with a library-wide capacity. Session-specific dimensions return UNSUPPORTED. Unknown identifiers and a null output return INVALID_ARGUMENT. Failure leaves the output unchanged.
size_t max_arity = 0;
maelys_datalog_status_t status = maelys_datalog_limit_get(
MAELYS_DATALOG_LIMIT_MAX_ARITY, &max_arity);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);
printf("maximum arity: %zu\n", max_arity);status: ok maximum arity: 4
limit_name()
#include <maelys/datalog.h>
const char *
maelys_datalog_limit_name(
maelys_datalog_limit_t limit
);const char *
Returns the stable budget name, such as MAX_RULES, or NULL for an unknown identifier.
const char *name = maelys_datalog_limit_name(MAELYS_DATALOG_LIMIT_MAX_RULES);
printf("limit name: %s\n", name ? name : "unknown");limit name: MAX_RULES