← Versioned state

State.MigrationResult

luastra/state

State.MigrationResult 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/state to this module's dependencies in luastra.json, then import it with require("luastra/state"). No capability is required for encoding, decoding, or migration. Persistence additionally needs luastra/host plus storage.get and storage.set.

How it fits

The type describes string fields, migration functions, or tagged decode/migration results.

When to use it

Use State.MigrationResult 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

ParameterType / valuesDescription
definitionMigrationSuccess | MigrationFailureExact alias, union, or callable contract represented by State.MigrationResult.

Error codes

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

CodeWhen it occurs
emptyThe encoded source state is empty or not a string.
too_largeThe encoded source state exceeds 4096 bytes.
invalid_target_versiontargetVersion is not an integer from 1 through 999.
invalid_migrationsThe migration collection is not a table.
malformedThe source version prefix is missing or invalid.
newer_versionThe source version is newer than the requested target.
too_many_migrationsThe migration would require more than 32 steps.
missing_migrationNo migration function exists for the current version.
migration_failedA migration function raised an error.
invalid_migrationA migration returned, encoded, or verified an invalid replacement.

SDK type flow

Produced by

State.migrate

What happens next

A checked snapshot or result annotation.

Failures and fixes

Malformed data, wrong versions, missing migration steps, excessive size, or non-string fields remain explicit failure branches. Do not silently replace corrupt security- or domain-sensitive values with defaults.

Availability

Public-source alpha API in 0.5.0-alpha; persistence support is host-dependent.

Exact declaration

export type MigrationResult = MigrationSuccess | MigrationFailure

Complete inventory

View all pages in Versioned state
← Previous: State.MigrationFailureNext: State.Migration →