Skip to content
Halyard
Project
Source code on Codeberg (opens in new tab)

Search

Menu

Runtime Errors

Halyard catches most errors at compile time through its type system. The errors on this page can only occur at runtime because they depend on values, environment, or external systems that are unknown during compilation.

Collection Bounds

Accessing a list or tuple element at an index that doesn't exist:

halyard
let items = [1, 2, 3]

items[10]

Tuple index out of bounds with a literal index is caught at compile time:

halyard
let triple = (1, 2, 3)

triple.5

Use List.nth for safe access that returns Maybe instead of crashing:

halyard
import List

let items = [10, 20, 30]

-- Safe access returns Maybe
case List.nth 1 items of
    Just value -> value
    Nothing -> 0

Division by Zero

When the divisor is a variable, the compiler cannot know its value:

halyard
let divisor = 0.0

10.0 / divisor

Guard against zero divisors before dividing:

halyard
import String

fn safeDivide : Int -> Int -> String
fn safeDivide a b =
    if b == 0 then
        "Cannot divide by zero"
    else
        "Result: " ++ String.fromInt (a // b)

safeDivide 10 0

Dividing by a literal 0 (e.g. x / 0) is caught at compile time.

Execution Limits

The VM limits the number of instructions to prevent infinite loops:

halyard
fn loop : Int -> Int
fn loop n = loop (n + 1)

loop 0  -- Execution limit exceeded

The allocation limit prevents creating data structures that are too large:

halyard
-- Allocating a list with millions of elements would hit the limit

IO Security

IO operations are disabled by default. Set environment variables to enable them:

ErrorCauseFix
IO operations are disabledIO not enabledSet HALYARD_IO_DISABLED=0
Write operations are disabledRead-only modeUnset HALYARD_IO_READ_ONLY
Access denied: path outside sandboxSandbox violationAccess files within HALYARD_IO_SANDBOX

See IO Security for configuration details.

HTTP Security

HTTP requests are disabled by default:

ErrorCauseFix
HTTP operations are disabledHTTP not enabledSet HALYARD_HTTP_DISABLED=0
HTTP request to host not allowedHost not in allowlistAdd host to HALYARD_HTTP_ALLOWED_HOSTS
HTTP errorNetwork failureCheck URL and connection

DataFrame Errors

DataFrame operations can fail at runtime when working with external data:

ErrorCause
DataFrame file errorFile not found or unreadable
DataFrame operation errorInvalid operation on data (e.g. aggregating non-numeric column)

Column name typos are caught at compile time when the schema is known (e.g. in the frame a DataFrame.readCsv with a literal path returns, once unwrapped with ? or in the Ok arm of a case).

Integer Overflow

Int is a 64-bit signed integer. When an arithmetic operation produces a value outside that range, the program stops with an Integer overflow runtime error. The result never wraps around, and it is never turned into a Float:

halyard
let big = 9223372036854775807

big - 1  -- 9223372036854775806
big + 1  -- Integer overflow: the result does not fit in Int

If your values can grow that large, compute with Decimal (exact) or Float (approximate) instead.

Summary

CategoryCompile-timeRuntime
Type mismatchesCaught for known typesSafety net for gradual typing
Division by zeroLiteral 0 caughtVariable divisor
Collection boundsLiteral index on tuplesVariable index
Field accessKnown record typesOpen/dynamic records
IO/HTTP/DataFrameSecurity config checkedFile/network errors
Execution limits--Always runtime