← Runtime data validation

Data.Failure

luastra/data

Data.Failure represents the unsuccessful branch of a bounded operation. Its stable code and structured context support control flow and safe diagnostics without parsing an exception message.

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.Failure on the unsuccessful branch of the related result. Read its stable fields for control flow or diagnostics; do not parse human-readable assertion or error text.

Fields or definition

ParameterType / valuesDescription
successfalseDiscriminator that must be checked before reading branch-specific fields.
valuenilValidated value available on the successful result branch.
errorValidationErrorBounded failure information, or nil on the successful branch.

Error codes

This is the complete closed vocabulary emitted by the named operation in this Source SDK contract.

CodeWhen it occurs
invalid_schemaThe supplied schema is not a valid Data.Schema value.
maximum_depthNested validation exceeded the supported schema depth.
schema_cycleThe schema recursively references itself.
expected_stringThe value at path is not a string.
too_shortA string contains fewer bytes than minBytes.
too_longA string contains more bytes than maxBytes.
expected_numberThe value is not a finite number.
expected_integerThe value is not an integer required by the schema.
too_smallA number is below the configured minimum.
too_largeA number is above the configured maximum.
expected_booleanThe value at path is not a boolean.
expected_arrayThe value is not a dense one-based array.
too_few_itemsAn array contains fewer items than minItems.
too_many_itemsAn array contains more items than maxItems.
expected_objectThe value at path is not an object table.
unexpected_fieldAn exact object contains a field absent from its schema.
unknown_schemaThe schema kind is not supported by this SDK version.

SDK type flow

Produced by

Data.decode

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 Failure = { success: false, value: nil, error: ValidationError }

Complete inventory

View all pages in Runtime data validation
← Previous: Data.SuccessNext: Data.Result →