Sakura Lang

Error codes

Every Sakura Lang diagnostic code with its explanation, a program that triggers it and the fixed program.

Every diagnostic code the compiler and the runtime report, with its explanation, a program that triggers it and, where one is checked in, the fixed program. Codes are stable and never renumbered (design §12.3); sakura explain <code> prints the same explanation offline, and a diagnostic's explanation_uri (sakura://explain/<code>) maps to /docs/errors/<code>. V codes are errors, W warnings and D runtime defects; the diagnostics reference describes the JSON records.

90 codes; 64 pages show a fixed program that the compiler's test suite checks.

Lex and parse

CodeTitleSummary
V0001syntax_errorThe parser expected a different token, or a delimiter was never closed.
V0002unterminatedA string literal, interpolation or block comment reaches the end of the file without being closed.
V0003int_literal_out_of_rangeAn Int literal is outside the 64-bit signed range [-2^63, 2^63-1] (design §2.2).
V0004invalid_characterThe source contains a character that cannot start any token.
V0005invalid_escapeA string contains an escape that is not one of \\ \" \n \r \t \0 \{ \} or \u{XXXXXX} (design §2.3).
V0006malformed_numberA numeric literal is malformed, such as 0x with no digits, 1. or .5.
V0007reserved_keywordThe word is reserved for a future edition: verify proof ghost control resume region spawn actor interface impl (design §2.1).
V0008nesting_limit_exceededExpressions, types, patterns or blocks nest deeper than the parser's limit (128).
V0009expected_terminatorTwo statements are on one line without ;, or junk follows a complete statement (design §2.4).
V0010chained_comparisonComparison operators do not chain (design §3.1).
V0011call_site_type_argumentsExpressions cannot take type arguments in v0 (design §3.2).
V0012keyword_expression_operandif, match, with, try, fn, handler and fail expressions cannot be operands of a binary or postfix operator without parentheses (design §3.2).
V0013invalid_assign_targetThe left side of = must be a var name or a field path on one (u.email = e).
V0014named_argumentCalls take positional arguments only (design §3.2 rule 13, §17.21); name: value exists only inside attribute arguments.

Names and modules

CodeTitleSummary
V1001duplicate_definitionTwo items in the same module and namespace have the same name (design §9).
V1002unresolved_nameNo value with this name is in scope.
V1003unresolved_typeNo type, effect, variant or error tag with this name is in scope.
V1004name_case_mismatchValues are lower_snake identifiers and types, variants, error tags and effects are UpperCamel (design §2.1).
V1005unresolved_moduleAn import names a module that does not exist in the snapshot, std, or the declared dependencies.
V1006private_itemThe item exists but this module cannot use it: it is not pub, or it is a constructor or field of a pub opaque type, which only the declaring module may use (design §9, §17.10).
V1007wrong_kindA name resolved to the wrong kind of item for where it is used: an effect where a type is expected, a type where a value is expected, and so on.
V1010unknown_attributeOnly these attributes exist in v0: @tool, @llm, @external, @total, @contract_test, @deprecated, @server, @test_only on items, and @trust("reason") as an expression (design §2.5).
V1011missing_bodyA function has no body.
V1012mixed_union_alternativestype X = A | B must be either all existing error tags (an error-union alias) or all new variants.
V1020recursive_lambdaLocal lambdas cannot refer to themselves.
V1030import_cycleModules import each other in a cycle; v0 forbids import cycles (design §9).
V1040assign_immutableOnly var bindings can be assigned; let bindings and parameters are immutable (design §8.1).
V1041jump_outside_loopbreak or continue appears outside a for or while loop (or crosses a function boundary: a break inside a lambda cannot leave the loop around the lambda).

Types

CodeTitleSummary
V2001type_mismatchAn expression has a different type from the one its context requires.
V2002arity_mismatchA function was called with the wrong number of arguments, or a pattern has the wrong number of fields.
V2003not_callableThe callee of a call expression is not a function: a value of another type is followed by (…).
V2004unknown_fieldThe record type has no field with this name, or a record literal is missing required fields or names an extra one.
V2005infinite_typeInference would need a type that contains itself (the occurs check failed).
V2010cannot_infer_typeThe type of an empty collection literal (or another binding) cannot be inferred from its uses.
V2015error_union_annotation_neededTwo different error unions meet in synthesis mode (for example the branches of an if).
V2031not_showA value whose type is not Show was interpolated or printed.
V2032constraint_not_satisfiedA type does not satisfy a constraint the operation requires: Eq, Ord, Hash or Schema (Show is V2031).
V2033opaque_not_schemaA Schema bound (Json.decode, Sql.query rows, Llm.generate, Cli.parse, Tool.of arguments, a property parameter) reaches an opaque type outside its declaring module, directly or through a field (design §17.130).
V2034refined_field_assignmentA field assignment changes a field of a var whose type, or the type of a prefix of the path, is a refined type (design §17.135).
V2040unused_valueA non-final expression statement produces a non-Unit value that is dropped.
V2041assign_captured_varA lambda, or a try body, assigns to a var declared outside it.
V2050hole_in_buildsakura build, sakura run and sakura test reject typed holes (?name).

Effects and handlers

CodeTitleSummary
V3001effect_not_allowedThe body performs an effect that the function's signature does not allow.
V3002effect_label_not_permittedA closed effect row was required to be empty or smaller, but an effect label had to be in it (row unification {A | r} ~ {} failed, design §5.2).
V3003try_unknown_failurestry without catch must name every failure of its body in Result<T, E>.
V3010invalid_operation_rowAn effect operation's row may contain only Fail<…> in v0 (design §5.5).
V3011handler_clause_mismatchA handler must provide exactly one clause per operation of its effect, with matching parameter counts (design §5.5).
V3012with_non_handlerwith was given something that is not a Handler<E, r> value.
V3020test_unhandled_effectTests run under deterministic default handlers for Clock, Random, Env, Console and Log (design §5.8).

Patterns

CodeTitleSummary
V4001non_exhaustive_matchA match does not cover every value.
V4002unreachable_armA match arm can never be reached because earlier arms already cover every value it matches.
V4003or_pattern_bindingsAll alternatives of an or-pattern must bind the same names with the same types (design §3.2).

Contracts and refinements

CodeTitleSummary
V5001impure_contractPredicates in where, requires, ensures and property bodies must be pure, terminating and deterministic: no loops, no recursion, and calls only to @total functions in the contract subset (design §7.1).
V5002refinement_checked_at_runtime (retired)Retired (design §17.87, §12.3): never reported.
V5003validate_target_not_refinedUntrusted.validate(u) takes its target V from the expected type Result<V, Violation>.
V5004literal_violates_refinementA literal stands where a refined type is expected, and the compiler evaluated the type's where clause on it: the predicate is false, or evaluating it defects (an integer division by zero, a failed requires of a function it calls).

Capabilities, resources and escape

CodeTitleSummary
V6001capability_constructionCapability values (Dir, NetScope, EnvScope, SecretStore) cannot be constructed by user code.
V6002scoped_value_escapeA scoped value escapes the with that bounds it (design §6.3, §17.70).
V6003resource_escapeA @resource value (v0: File) escapes the callback of the operation that introduced it: the callback returns a type containing it (directly, or inside a record, list or closure), or the value is stored in handler var state (design §8.4, §17.70).
V6010non_std_effect_in_mainmain's effect row may contain only std effects, because only they have host root handlers (design §9).

Packages and build

CodeTitleSummary
V8001missing_entry_pointsakura run needs pub fn main() -> Unit ! {…} in the program it runs (design §9).
V8002reserved_package_namesakura.toml names its package std or main (design §9, §17.131).
V8003abi_version_mismatchThe WASM module was compiled against a runtime ABI this host does not implement (runtime/rt/ABI.md §0): its major version differs, or its minor version is newer than the host's, so it may need imports the host lacks.
V8004target_unsupported_externalA user package declares an @external(js, …) function, and --target wasm has no JavaScript to call (design §17.81): the WASM backend runs std's host operations through the runtime's own imports only.
V8020spec_frozenA patch modifies a frozen symbol's signature, effect row, error union, contracts, or a test body (design §7.3).

Internal

CodeTitleSummary
V9001internal_errorThe compiler hit a bug.
V9002phase_unavailableA compiler phase needed by this command is not implemented yet in this pre-alpha build.

Warnings

CodeTitleSummary
W1002shadowed_importA local binding shadows an imported name.
W4010catch_all_on_open_unionA catch uses _ => … on an error union that may grow.
W5005linear_contract_on_hot_pathA requires, ensures, where or property requires clause calls List.all, List.any, List.contains or String.contains on a parameter (or it), so every check scans the whole value (design §7.2, §17.72).
W7001property_discard_budgetA property discarded more than 90% of its generated inputs, so it tested almost nothing (design §7.4, §17.64).
W7002vacuous_obligationA contract obligation was proved only because the assumptions on its path are contradictory, so the path can never run and the proof says nothing useful (design §17.98, §17.105).
W8001copy_on_writeAn update to a shared collection is forced to copy inside a loop because another reference retains the old value (design §8.2).

Runtime defects

CodeTitleSummary
D001int_overflowChecked Int arithmetic overflowed 64 bits.
D002division_by_zero/ or % was evaluated with a divisor of 0.
D003int_beyond_js_safe_rangeOn the JS backend, an Int left the exactly representable range ±(2^53−1).
D004float_not_finiteFloat.round or a float-to-int conversion was given NaN or ±∞.
D010refinement_violatedA checked introduction such as Email.from(s) received a value that fails the refinement.
D011contract_evaluation_failedEvaluating a contract predicate itself defected (for example it overflowed).
D020precondition_violatedA requires clause failed on entry.
D021postcondition_violatedAn ensures clause failed on normal return.
D030option_expect_noneOption.expect was called on None.
D031string_slice_not_char_boundaryString.slice was given a byte offset that is not on a UTF-8 character boundary.
D090runtime_internal_errorThe runtime hit a bug or an exhausted host resource (for example a JS exception that is not a Sakura Lang defect).
D091host_failureA host operation failed outside Sakura Lang's control (for example a rejected host promise).
D092rc_overflowOn the WASM runtime, an object's reference count would pass 2^32 − 1.
D093finalizer_failedOn the WASM runtime, a finalizer (the cleanup of Fs.with_file and similar) failed with an error.
D094context_escapedOn the WASM runtime, an operation callback was called after its handler's perform site was gone.
D095fiber_retiredOn the WASM runtime, join was called on a fiber that had already been retired.
D096heap_exhaustedOn the WASM runtime, the heap limit (SAKURA_MAX_HEAP) was reached or memory could not grow.
Edit on GitHub

On this page