Esc
Start typing to search...

Runtime Errors

Keel 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:

let items = [1, 2, 3]

items[10]
Try it

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

let triple = (1, 2, 3)

triple.5
Try it

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

import List

let items = [10, 20, 30]

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

Division by Zero

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

let divisor = 0

10 / divisor
Try it

Guard against zero divisors before dividing:

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
Try it

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:

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:

-- 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 KEEL_IO_DISABLED=0
Write operations are disabledRead-only modeUnset KEEL_IO_READ_ONLY
Access denied: path outside sandboxSandbox violationAccess files within KEEL_IO_SANDBOX

See IO Security for configuration details.

HTTP Security

HTTP requests are disabled by default:

ErrorCauseFix
HTTP operations are disabledHTTP not enabledSet KEEL_HTTP_DISABLED=0
HTTP request to host not allowedHost not in allowlistAdd host to KEEL_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. after DataFrame.readCsv with a literal path).

Integer Overflow

When an integer operation produces a value outside the Int range:

-- Integer overflow happens when values exceed 64-bit signed range
-- Keel automatically promotes to Float when overflow is detected

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