Errors

Luma has two kinds of errors:

KindWhenExample
compile errorbefore the program runs: the program isn’t valid Lumaa misspelled name, mixing int and str
runtime errorwhile the program runs: an operation is impossibledivision by zero, a list index outside the list

Both print a message with the place in the file where the problem is:

file.luma:LINE:COLUMN: message

Both make luma (or the compiled program) exit with code 1.

Compile errors

When a program has a compile error, nothing runs, not even the lines before the error. Luma reports the first error it finds.

Some examples:

hello.luma:1:1: unknown function "prnt"
hello.luma:3:9: operator + needs both sides to have the same type, got int and str
hello.luma:2:7: undefined variable cout
hello.luma:4:4: condition must be a bool, got int (compare explicitly, e.g. x > 0)
hello.luma:1:11: 256 does not fit in a byte (0..255)
hello.luma:2:6: '=' assigns a value; use '==' to compare
hello.luma:5:1: x is already declared at 1:1
hello.luma:1:7: a number cannot start with '.' (write 0.5)

The messages try to say what to do, not only what is wrong.

Runtime errors

A runtime error stops the program at that point, unless it happens inside a try block, which can catch it. Everything printed before it stays printed:

print("before")
zero: int = 0
print(1 / zero)
print("after")

Output:

before
example.luma:3:9: runtime error: division by zero

The message goes to the error output (stderr), and the program exits with code 1. A compiled program prints the very same message, including the file name and position.

List of runtime errors

CodeErrorCause
1runtime error: division by zero/ or % on int or byte with a zero right side
2runtime error: index N out of range (length M)reading, changing or removing a list element that doesn’t exist, including negative indexes
3runtime error: key K not foundreading or removing a map key that isn’t in the map (check with has first)
3runtime error: element E not foundremoving a value that isn’t in the set
4runtime error: cannot throw nil / cannot read .code of nilusing a nil error
5runtime error: error code N is reserved ...error(code, ...) with a code below 100
6runtime error: invalid input "TEXT": expected an intprompt read a line that isn’t a value of the type wanted
7runtime error: end of inputprompt with nothing left to read
8runtime error: file not found: PATHreading, deleting or getting the size of a file that isn’t there
9runtime error: cannot write PATH: REASONa file operation failed: permission denied, it is a folder, the folder does not exist, …
10runtime error: too many nested calls (more than 10000)a function calls itself (or others) too deep, usually a recursion that never stops
11runtime error: cannot convert "abc" to an intconvert of a value that doesn’t fit the type; also JSON that isn’t valid or not of the kind used
18runtime error: files and folders aren't available in the playground (or the network, or running other programs)a program run with luma run -sandbox, as the playground does, tried to reach the system
–runtime error: out of memorythe operating system has no more memory to give (compiled programs only; can’t be caught)

All of these except out of memory can be caught with try; the code is then in err.code. Errors your program raises with throw are reported as error CODE: message when nothing catches them. See Error handling.

Float division by zero is not an error: it gives inf or nan.