Data.Result
luastra/dataData.Result is a discriminated union covering successful output and bounded failure. Branching on success narrows the value to the correct exported record and makes error handling explicit.
Before you use it
Add luastra/data to this module's dependencies in luastra.json, then import it with require("luastra/data"). No host capability is required. Define schemas outside render when they are reused.
How it fits
The exported type describes schemas or the tagged success/failure result returned by Data.decode.
When to use it
Use Data.Result at the boundary where untrusted or versioned input is decoded. Branch on result.success before reading value or error so both outcomes remain explicit and type-safe.
Fields or definition
| Parameter | Type / values | Description |
|---|---|---|
| definition | Success | Failure | Exact alias, union, or callable contract represented by Data.Result. |
Error codes
This is the complete closed vocabulary emitted by the named operation in this Source SDK contract.
| Code | When it occurs |
|---|---|
| invalid_schema | The supplied schema is not a valid Data.Schema value. |
| maximum_depth | Nested validation exceeded the supported schema depth. |
| schema_cycle | The schema recursively references itself. |
| expected_string | The value at path is not a string. |
| too_short | A string contains fewer bytes than minBytes. |
| too_long | A string contains more bytes than maxBytes. |
| expected_number | The value is not a finite number. |
| expected_integer | The value is not an integer required by the schema. |
| too_small | A number is below the configured minimum. |
| too_large | A number is above the configured maximum. |
| expected_boolean | The value at path is not a boolean. |
| expected_array | The value is not a dense one-based array. |
| too_few_items | An array contains fewer items than minItems. |
| too_many_items | An array contains more items than maxItems. |
| expected_object | The value at path is not an object table. |
| unexpected_field | An exact object contains a field absent from its schema. |
| unknown_schema | The schema kind is not supported by this SDK version. |
SDK type flow
Produced by
What happens next
A checked schema/result annotation.
Failures and fixes
Ordinary invalid input is a Data.decode failure, not an exception. Invalid schema options are programmer errors and fail immediately. String bounds count UTF-8 bytes; Data.string has no pattern option in this alpha.
Availability
Public-source alpha API in 0.5.0-alpha; host-independent and synchronous.
Exact declaration
export type Result = Success | Failure