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 itTuple index out of bounds with a literal index is caught at compile time:
let triple = (1, 2, 3)
triple.5
Try itUse 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 itDivision by Zero
When the divisor is a variable, the compiler cannot know its value:
let divisor = 0
10 / divisor
Try itGuard 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 itDividing 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:
| Error | Cause | Fix |
|---|---|---|
IO operations are disabled | IO not enabled | Set KEEL_IO_DISABLED=0 |
Write operations are disabled | Read-only mode | Unset KEEL_IO_READ_ONLY |
Access denied: path outside sandbox | Sandbox violation | Access files within KEEL_IO_SANDBOX |
See IO Security for configuration details.
HTTP Security
HTTP requests are disabled by default:
| Error | Cause | Fix |
|---|---|---|
HTTP operations are disabled | HTTP not enabled | Set KEEL_HTTP_DISABLED=0 |
HTTP request to host not allowed | Host not in allowlist | Add host to KEEL_HTTP_ALLOWED_HOSTS |
HTTP error | Network failure | Check URL and connection |
DataFrame Errors
DataFrame operations can fail at runtime when working with external data:
| Error | Cause |
|---|---|
DataFrame file error | File not found or unreadable |
DataFrame operation error | Invalid 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.readCsvwith 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
| Category | Compile-time | Runtime |
|---|---|---|
| Type mismatches | Caught for known types | Safety net for gradual typing |
| Division by zero | Literal 0 caught | Variable divisor |
| Collection bounds | Literal index on tuples | Variable index |
| Field access | Known record types | Open/dynamic records |
| IO/HTTP/DataFrame | Security config checked | File/network errors |
| Execution limits | -- | Always runtime |