CLS never shows a bare error message and stops. Every error produced at runtime or during parsing comes with a full traceback: the chain of imports that led to the failing file, the numbered call stack with one source-context line per frame, and a caret pointing at the exact column where the error occurred. This is not optional — the rule is enforced at the architecture level: the interpreter only exposesDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/elfrask/cls/llms.txt
Use this file to discover all available pages before exploring further.
format_error (which always renders the full report), not a raw message getter.
ClsError Variants
All errors in CLS are variants ofClsError, defined in cls-core/src/error/mod.rs:
| Variant | When used |
|---|---|
SyntaxError(String) | Legacy variant; span is embedded in the message text as (línea N, columna M). Kept for backward compatibility. |
SyntaxErrorAt(String, Span) | Modern structured variant. Message is clean; the Span carries start_line, start_col, end_line, end_col separately. |
RuntimeError(String) | Error thrown during tree-walking interpretation (division by zero, undefined variable, etc.). |
TypeError(String) | Type mismatch detected by the interpreter or type checker. |
CompileError(String) | Error emitted during compilation or code generation phases. |
IoError(std::io::Error) | File read/write failure; automatically converted from std::io::Error via #[from]. |
ConfigError(String) | Invalid or missing project configuration. |
ClsResult<T> is a type alias for Result<T, ClsError> used throughout cls-core and cls-runtime.Syntax Error Factory
New syntax errors should always be created via the centralised factory:SyntaxErrorAt with a clean message — no location embedded in the string. The Span carries the position so the formatter can render it uniformly regardless of the output format.
The legacy extract_line_col helper is only used as a fallback to parse (línea N, columna M) out of pre-existing RuntimeError strings. It is not a public API to reach for in new code.
ErrorReport — The Full Context Object
The formatter never operates on a bareClsError. It always receives an ErrorReport:
| Constructor | Use case |
|---|---|
ErrorReport::from_runtime(error, stack, import_trace, source_file) | Runtime errors from the interpreter |
ErrorReport::from_syntax(error, source, source_file) | Parse/lex errors where the source string is already in memory |
ErrorReport::from_config(error) | Configuration errors with no file context |
StackFrame holds a function name, an optional Span, and the source file path. Each ImportFrame holds the module name, file, and the line/col of the import statement.
ErrorFormat — Output Formats
Plain
Human-readable text with no terminal escape codes. Suitable for log files and CI output where ANSI is not rendered.
Console
ANSI-coloured output using codes from
cls_core::ansi. Frame numbers in cyan, arrows in yellow, error labels in magenta, carets in red.Html
Output wrapped in
<pre class="cls-error">. Inline style attributes carry colours matching the Console palette. Suitable for web playgrounds.Json
Fully structured JSON containing
error, message, file, span, stack, and imports arrays. Designed for editor integrations and language servers.API Functions
Runtime Traceback Format
When a runtime error occurs,format_error with ErrorFormat::Console (or Plain) renders this structure:
- Line 1: header —
Error de ejecución:for runtime errors,Error en 'file':for syntax errors. - Numbered frames: one per entry, in order: import chain first, then call stack, then the error site.
- Import frame:
N. En file:line:col - Call frame with location:
N. En file:line:col → functionName - Call frame without location:
N. → functionName (file) - Error frame:
N. En file:line:col [Error Label]
- Import frame:
- Source context: immediately below the frame header, if the source line is available:
The caret (
^) is aligned to the column, accounting for tab expansion (tabs count as 4 spaces). - Final line:
Error: <clean message>— the message with theError de X:prefix stripped.
The call stack is not popped when an error propagates — it is preserved intact so the full traceback can be rendered. A
try/catch block restores the stack depth after catching.Type Checker Output Format (clx check)
The type checker produces Diagnostic values with [ERROR] or [WARN] severity. The output format is single-level — no import trace, no call stack:
[ERROR]is rendered in red;[WARN]in yellow; a clean pass prints a green success message.- The
(line:col)position appears in grey next to the message. - The caret is coloured to match the severity.
Rules by Context
clx check — type checker diagnostics
clx check — type checker diagnostics
- Shows single-level diagnostics only:
file:line:col+ source line + caret. - No import trace.
- No numbered call stack.
- Severity prefix:
[ERROR](red) or[WARN](yellow). - A file with no errors prints a green “OK” line.
clx run / clxr / build — runtime and compile errors
clx run / clxr / build — runtime and compile errors
The full traceback is mandatory. These rules are enforced:
- Always include the import trace (even if empty — the outer frame is still printed).
- Always include the numbered call stack with one source-context block per frame.
- Always include the error site frame with caret.
- Never show only the error message.
show_runtime_error (which calls format_error internally with the full ErrorReport) is sufficient to comply.JSON Error Structure
ErrorFormat::Json produces a JSON object suitable for editor integrations:
error field contains the Debug representation of the ClsError variant. message contains only the clean user-facing message (prefix stripped).
In-Language Error Handling
CLS exposesthrow and try/catch/finally directly in the language:
The caught value
e is a String containing the error message. The call stack depth is restored to the level it was at before the try block when the catch clause runs — frames pushed inside the try block are discarded from the stack (but were used to build the traceback before the catch occurred).