Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Error Handling

All runtime operations that can fail return Result<T, RuntimeError>.

RuntimeError variants

Host errors

These indicate a bug in your code — the host called the API incorrectly.

VariantWhen
InvalidChoiceIndexchoose() called with an index outside the valid range
NotWaitingForChoicechoose() called when story isn’t in WaitingForChoice status
StoryEndedTried to continue a story that has permanently ended
UnknownFlowReferenced a named flow that doesn’t exist
FlowAlreadyExistsTried to spawn a flow with a name that’s already active
StepLimitExceededSafety limit hit — possible infinite loop in the story

Story errors

These indicate a problem in the ink source or an unsupported feature.

VariantWhen
TypeErrorType mismatch in an ink expression (e.g., adding a string to a list)
DivisionByZeroDivision or modulo by zero in an ink expression
UnresolvedExternalCallStory calls an external function with no handler provided
UnimplementedThe story uses an opcode not yet supported by the VM

Internal errors

These typically indicate a compiler bug — the bytecode is malformed.

VariantWhen
DecodeCorrupt or incompatible .inkb file
UnresolvedDefinitionLinker can’t find a referenced definition
NoRootContainerStory has no entry point
StackUnderflowValue stack empty when an operand was expected
CallStackUnderflowNo call frame to return to
ContainerStackUnderflowNo container to pop from the container stack
UnresolvedGlobalGlobal variable lookup failed
CaptureUnderflowOutput capture stack mismatch

Recovery

Host errors are recoverable — fix the calling code and retry. Story errors may be recoverable depending on context. Internal errors generally indicate broken bytecode and are not recoverable.