Error Methods

Errors in Risor are first-class values that carry diagnostic information about what went wrong and where. You can create error values with the error() built-in function and inspect them using the methods described here.

Method Reference

MethodDescription
message()The error message string
error()Alias for message(), returns the error message string
kind()The error kind as a string (e.g., "type", "value", "error")
line()Source line number where the error originated
column()Source column number where the error originated
filename()Source filename where the error originated
source()Source code context around the error
stack()Full stack trace as a list of maps

Creating Errors

Use the error() built-in to create an error value. This does not throw or halt execution. It simply returns an error as a value.

let err = error("something went wrong")
type(err)   // "error"

The error() function supports format arguments like sprintf:

let err = error("file not found: %s", "config.json")

Inspecting Errors

message

Return the error message as a string.

let err = error("something went wrong")
err.message()    // "something went wrong"

error

Alias for message(). Returns the error message as a string.

let err = error("something went wrong")
err.error()    // "something went wrong"

kind

Return the error kind as a string. The kind indicates the category of the error, such as "type", "value", or "error".

let err = error("something went wrong")
err.kind()    // e.g. "error"

line

Return the source line number where the error was created.

let err = error("oops")
err.line()    // e.g. 3

column

Return the source column number where the error was created.

let err = error("oops")
err.column()    // e.g. 11

filename

Return the source filename where the error was created.

let err = error("oops")
err.filename()    // e.g. "main.risor"

source

Return the source code context around where the error was created.

let err = error("oops")
err.source()    // source code snippet

stack

Return the full stack trace as a list of maps. Each map in the list contains the keys function, line, column, and filename. This is useful for debugging errors that propagate through multiple function calls.

let err = error("oops")
err.stack()    // e.g. [{"function": "main", "line": 1, "column": 11, "filename": "main.risor"}]

Example: Error Handling Pattern

Errors are commonly used with conditional checks to handle failure cases:

let result = some_operation()
 
if (type(result) == "error") {
    result.message()   // the error message
    result.line()      // source line number
    result.stack()     // stack trace
}

Risor © 2026 Deep Noodle