Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/boblio-max/origin/llms.txt

Use this file to discover all available pages before exploring further.

Origin wraps every runtime error in a structured, human-readable report that includes the file name, the exact line number where the failure occurred, and a plain-English explanation of what went wrong. This behavior is implemented in errors.py and fires automatically whenever an unhandled exception propagates out of a running script. For errors you anticipate, the try/except/else construct lets you handle them gracefully without crashing the program.

try / except / else Syntax

Wrap any statement or block of statements in a try block. If an exception is raised inside the try body, execution jumps to the except block. If no exception occurs, the optional else block runs after the try body completes:
try {
    let x: int = int("not-a-number")
    print x
} except {
    print "Conversion failed — value was not a valid integer."
} else {
    print "Conversion succeeded."
}

Multiple except Blocks

You can chain more than one except block after a single try. Each except catches any unhandled exception in sequence — the first matching block runs, then control continues after the chain:
try {
    let val: int = risky_operation()
} except {
    print "First handler: something went wrong."
} except {
    print "Second handler: reached if first re-raises."
}
except currently catches all exceptions without type filtering. Origin does not yet support typed catches such as except TypeError. All except blocks compile to Python’s bare except Exception:.

Runtime Error Format

When an unhandled error reaches the top level, Origin’s errors.py module prints a formatted report to the console. The report includes the file path, the line number, the translated error message, and a snippet of the offending source line with a caret pointer:
==================================================
 [!] ORIGIN RUNTIME ERROR
==================================================
 Location: main.or (Line 5)
 Message:  Unknown Variable: I don't recognize 'x'. Did you forget to define it with 'let'?
--------------------------------------------------
 5 | print x
     ^
==================================================

Friendly Error Translations

The translate_python_error function in errors.py maps common Python exceptions to plain-English Origin messages:
Python ExceptionOrigin Message
NameErrorUnknown Variable — “I don’t recognize '<name>'. Did you forget to define it with 'let'?”
TypeError (string concat)Type Mismatch — “You’re trying to add a Number to a Piece of Text. Use 'str()' to convert the number first.”
TypeError (operand mismatch)Math Error — “You’re trying to do math with two things that don’t match (like a Number and a List).”
ZeroDivisionErrorMath Error — “You tried to divide by zero! Math doesn’t like that.”
IndexErrorRange Error — “You tried to access an item that doesn’t exist in that List.”
KeyErrorKey Error — “I couldn’t find '<key>' in that Dictionary.”
Any otherGeneral Error — the raw Python message is forwarded.

Raising Exceptions from Inline Python

The raise keyword is reserved in Origin’s lexer but is not yet handled by the parser as a standalone Origin statement. To raise exceptions from Origin scripts, use a py { } block, which passes raw Python directly to the interpreter:
py {
    raise ValueError("Custom error from inline Python")
}
raise and assert are both reserved keywords in the lexer but are not yet implemented as native Origin statements. Use py { } blocks to access Python’s raise and assert directly until native support is added in a future release.

Build docs developers (and LLMs) love