FerrisScript Documentation

FerrisScript Error Codes Reference

This document provides a comprehensive reference for all error codes in FerrisScript. Each error includes a unique code, description, common causes, examples, and guidance on how to fix it.

Table of Contents

Overview

FerrisScript uses structured error codes to help you quickly identify and fix issues in your code. Each error code follows the format Error[EXXX]: where XXX is a unique number in a specific range:

Error Format

Compiler errors (lexical, syntax, type) include rich context with source code highlighting:

Error[E200]: Type mismatch
  Expected: i32
  Found: f32
  |
5 | let x: i32 = 3.14;
  |              ^^^^ Expected 'i32', found 'f32'

Runtime errors use a simpler format:

Error[E413]: Division by zero
Error[E401]: Undefined variable: 'foo'

Error Categories

Lexical Errors (E001-E099)

Errors that occur during tokenization of the source code.

E001: Invalid Character

Description: An invalid or unexpected character was encountered in the source code.

Common Causes:

Example:

let x = 5 @ 3;  // @ is not a valid operator

Error Message:

Error[E001]: Invalid character
  |
1 | let x = 5 @ 3;
  |           ^ Unexpected character '@' at line 1, column 11

How to Fix:

See Also: E002, E003

Related Codes: E002, E003


E002: Unterminated String

Description: A string literal was started but never closed with a closing quote.

Common Causes:

Example:

let msg = "Hello world;  // Missing closing quote

Error Message:

Error[E002]: Unterminated string
  |
1 | let msg = "Hello world;
  |           ^^^^^^^^^^^^^ String literal not closed at line 1, column 11

How to Fix:

See Also: E001

Related Codes: E001


E003: Invalid Number Format

Description: A number literal has an invalid format.

Common Causes:

Example:

let x = 3.14.159;  // Two decimal points

Error Message:

Error[E003]: Invalid number format
  |
1 | let x = 3.14.159;
  |         ^^^^^^^^ Invalid number format at line 1, column 9

How to Fix:

Related Codes: E001


Syntax Errors (E100-E199)

Errors that occur during parsing of the token stream into an Abstract Syntax Tree (AST).

E100: Unexpected Token

Description: The parser encountered a token that doesn’t fit the expected syntax.

Common Causes:

Example:

let x = 5
let y = 10;  // Missing semicolon on previous line

Error Message:

Error[E100]: Unexpected token
  |
2 | let y = 10;
  | ^^^ Expected ';', found 'let' at line 2, column 1

How to Fix:

See Also: E101, E102

Related Codes: E101, E102


E101: Invalid Top-Level Item

Description: An invalid statement or declaration was found at the top level of the program.

Common Causes:

Example:

x = 5;  // Assignment at top level (use 'let' or 'let mut')

Error Message:

Error[E101]: Invalid top-level item
  |
1 | x = 5;
  | ^ Expected function or global variable declaration at line 1, column 1

How to Fix:

Related Codes: E100, E102


E102: Expected Expression

Description: The parser expected an expression but found something else.

Common Causes:

Example:

let x = 5 + ;  // Missing right operand

Error Message:

Error[E102]: Expected expression
  |
1 | let x = 5 + ;
  |             ^ Expected expression, found ';' at line 1, column 13

How to Fix:

Related Codes: E100, E103


E103: Expected Field Name

Description: A field name was expected in field access or object construction but wasn’t found.

Common Causes:

Example:

let val = vector2.;  // Missing field name

Error Message:

Error[E103]: Expected field name
  |
1 | let val = vector2.;
  |                   ^ Expected field name after '.', found ';' at line 1, column 19

How to Fix:

Related Codes: E102, E215


E104: Expected Statement

Description: The parser expected a statement but found something else.

Common Causes:

Example:

fn test() {
    +  // Expression without context
}

Error Message:

Error[E104]: Expected statement
  |
2 |     +
  |     ^ Expected statement, found '+' at line 2, column 5

How to Fix:

Related Codes: E100, E102


E105: Expected Type

Description: A type annotation was expected but not provided or invalid.

Common Causes:

Example:

fn add(a: , b: i32) -> i32 {  // Missing type for 'a'
    return a + b;
}

Error Message:

Error[E105]: Expected type
  |
1 | fn add(a: , b: i32) -> i32 {
  |           ^ Expected type annotation, found ',' at line 1, column 11

How to Fix:

Related Codes: E110, E218


E106: Expected Identifier

Description: An identifier (name) was expected but not found.

Common Causes:

Example:

let = 5;  // Missing variable name

Error Message:

Error[E106]: Expected identifier
  |
1 | let = 5;
  |     ^ Expected identifier, found '=' at line 1, column 5

How to Fix:

Related Codes: E109


E107: Expected Block

Description: A code block (enclosed in curly braces) was expected but not found.

Common Causes:

Example:

fn test()
    return 5;  // Missing braces around function body

Error Message:

Error[E107]: Expected block
  |
2 |     return 5;
  |     ^^^^^^ Expected '{', found 'return' at line 2, column 5

How to Fix:

Related Codes: E100


E108: Expected Parameter

Description: A function parameter was expected but not properly formed.

Common Causes:

Example:

fn add(a: i32, ) -> i32 {  // Trailing comma without parameter
    return a + 1;
}

Error Message:

Error[E108]: Expected parameter
  |
1 | fn add(a: i32, ) -> i32 {
  |                ^ Expected parameter, found ')' at line 1, column 16

How to Fix:

Related Codes: E111


E109: Invalid Identifier

Description: An identifier name is invalid or uses a reserved keyword.

Common Causes:

Example:

let fn = 5;  // 'fn' is a keyword

Error Message:

Error[E109]: Invalid identifier
  |
1 | let fn = 5;
  |     ^^ 'fn' is a reserved keyword and cannot be used as an identifier at line 1, column 5

How to Fix:

Related Codes: E106


E110: Invalid Type

Description: An invalid or unknown type was specified.

Common Causes:

Example:

let x: int = 5;  // 'int' is not valid, should be 'i32'

Error Message:

Error[E110]: Invalid type
  |
1 | let x: int = 5;
  |        ^^^ Unknown type 'int' at line 1, column 8

How to Fix:

Related Codes: E105, E218


E111: Invalid Parameter

Description: A function parameter has invalid syntax or structure.

Common Causes:

Example:

fn add(a i32, b: i32) -> i32 {  // Missing colon
    return a + b;
}

Error Message:

Error[E111]: Invalid parameter
  |
1 | fn add(a i32, b: i32) -> i32 {
  |        ^^^^^ Expected ':' after parameter name at line 1, column 8

How to Fix:

Related Codes: E108


E112: Invalid Return Type

Description: The return type of a function has invalid syntax.

Common Causes:

Example:

fn test() -> {  // Missing return type
    return 5;
}

Error Message:

Error[E112]: Invalid return type
  |
1 | fn test() -> {
  |              ^ Expected return type after '->', found '{' at line 1, column 14

How to Fix:

Related Codes: E110


E113: Invalid Operator

Description: An invalid or unexpected operator was encountered.

Common Causes:

Example:

let x = 5 ** 2;  // '**' is not a valid operator

Error Message:

Error[E113]: Invalid operator
  |
1 | let x = 5 ** 2;
  |           ^^ Unsupported or invalid operator at line 1, column 11

How to Fix:

Related Codes: E100


Type Errors (E200-E299)

Errors that occur during type checking of the AST.

E200: Type Mismatch

Description: An expression or value has a type that doesn’t match what’s expected.

Common Causes:

Example:

let x: i32 = 3.14;  // Assigning f32 to i32 variable

Error Message:

Error[E200]: Type mismatch
  Expected: i32
  Found: f32
  |
1 | let x: i32 = 3.14;
  |              ^^^^ Expected 'i32', found 'f32'

How to Fix:

See Also: E219, E205, E211

Related Codes: E219, E205


E201: Undefined Variable

Description: A variable is used before it’s declared or is not in scope.

Common Causes:

Example:

fn test() {
    let x = y + 5;  // 'y' is not defined
}

Error Message:

Error[E201]: Undefined variable 'y'
  |
2 |     let x = y + 5;
  |             ^ Variable must be declared before use

How to Fix:

See Also: E401 (runtime version)

Related Codes: E401


E202: Undefined Function

Description: A function is called but hasn’t been defined.

Common Causes:

Example:

fn main() {
    let x = add(5, 3);  // 'add' function not defined
}

Error Message:

Error[E202]: Undefined function 'add'
  |
2 |     let x = add(5, 3);
  |             ^^^ Function not found

How to Fix:

See Also: E415 (runtime version), E402

Related Codes: E415


E204: Wrong Number of Arguments

Description: A function is called with the wrong number of arguments.

Common Causes:

Example:

fn add(a: i32, b: i32) -> i32 {
    return a + b;
}

fn main() {
    let x = add(5);  // Missing second argument
}

Error Message:

Error[E204]: Wrong number of arguments
  Function 'add' expects 2 arguments, got 1
  |
6 |     let x = add(5);
  |             ^^^^^^ Expected 2 arguments

How to Fix:

Related Codes: E416


E205: Incorrect Argument Type

Description: An argument passed to a function has the wrong type.

Common Causes:

Example:

fn greet(name: String) {
    print(name);
}

fn main() {
    greet(42);  // Passing i32 instead of String
}

Error Message:

Error[E205]: Incorrect argument type
  Parameter 'name' expects String, got i32
  |
6 |     greet(42);
  |           ^^ Expected 'String', found 'i32'

How to Fix:

Related Codes: E200


E209: Invalid Field Access

Description: Attempting to access a field on a value that doesn’t support field access.

Common Causes:

Example:

let x: i32 = 42;
let y = x.field;  // Can't access field on i32

Error Message:

Error[E209]: Invalid field access
  Cannot access field 'field' on i32
  |
2 | let y = x.field;
  |         ^ i32 does not have fields

How to Fix:

Related Codes: E215, E408


E211: Condition Must Be Boolean

Description: A condition in an if statement or while loop must be a boolean expression.

Common Causes:

Example:

let x = 5;
if x {  // 'x' is i32, not bool
    print("true");
}

Error Message:

Error[E211]: Condition must be boolean
  Condition in if/while must be type bool, got i32
  |
2 | if x {
  |    ^ Expected bool, found i32

How to Fix:

Related Codes: E200


E212: Binary Operation Type Error

Description: A binary operation has operands of incompatible types.

Common Causes:

Example:

let x = "hello" + 42;  // Can't add String and i32

Error Message:

Error[E212]: Binary operation type error
  Cannot apply '+' to String and i32
  |
1 | let x = "hello" + 42;
  |         ^^^^^^^^^^^^^ Incompatible types

How to Fix:

Related Codes: E200


E213: Unary Operation Type Error

Description: A unary operation is applied to an incompatible type.

Common Causes:

Example:

let x = -"hello";  // Can't negate a string

Error Message:

Error[E213]: Unary operation type error
  Cannot apply '-' to String
  |
1 | let x = -"hello";
  |         ^^^^^^^^ '-' requires numeric type

How to Fix:

Related Codes: E414


E215: Field Not Found

Description: Attempting to access a field that doesn’t exist on the object.

Common Causes:

Example:

let vec = Vector2 { x: 1.0, y: 2.0 };
let z = vec.z;  // Vector2 doesn't have 'z' field

Error Message:

Error[E215]: Field not found
  Vector2 has no field 'z'
  |
2 | let z = vec.z;
  |             ^ Valid fields are: x, y

How to Fix:

See Also: E407 (runtime version), E103, E209

Related Codes: E407, E103


E218: Type Annotation Required

Description: A type cannot be inferred and must be explicitly annotated.

Common Causes:

Example:

let x;  // No type or initial value

Error Message:

Error[E218]: Type annotation required
  Cannot infer type for 'x'
  |
1 | let x;
  |     ^ Provide type annotation or initial value

How to Fix:

Related Codes: E105, E110


E219: Incompatible Types in Assignment

Description: Cannot assign a value to a variable due to type incompatibility.

Common Causes:

Example:

let mut x = 5;
x = "hello";  // Can't assign String to i32 variable

Error Message:

Error[E219]: Incompatible types in assignment
  Cannot assign String to variable of type i32
  |
2 | x = "hello";
  |     ^^^^^^^ Expected i32, found String

How to Fix:

Related Codes: E200


Semantic Errors (E300-E399)

Errors related to signal declarations and usage.

E301: Signal Already Defined

Description: A signal with the same name has already been declared in the current scope.

Common Causes:

Example:

signal health_changed(old: i32, new: i32);
signal health_changed(value: i32);  // Error: signal already defined

Error Message:

Error[E301]: Signal already defined
  Signal 'health_changed' is already defined
  |
2 | signal health_changed(value: i32);
  |        ^^^^^^^^^^^^^^ Signal already declared at line 1

How to Fix:

Related Codes: E302, E303, E304


E302: Signal Not Defined

Description: Attempting to emit a signal that has not been declared.

Common Causes:

Example:

fn take_damage() {
    emit_signal("health_change", 100, 75);  // Typo: should be "health_changed"
}

Error Message:

Error[E302]: Signal not defined
  Signal 'health_change' is not defined
  |
2 |     emit_signal("health_change", 100, 75);
  |                 ^^^^^^^^^^^^^^^ Signal not declared
  |
  = help: Did you mean 'health_changed'?

How to Fix:

Related Codes: E301, E303, E304


E303: Signal Parameter Count Mismatch

Description: The number of arguments provided to emit_signal doesn’t match the signal’s declared parameter count.

Common Causes:

Example:

signal health_changed(old: i32, new: i32);

fn take_damage() {
    emit_signal("health_changed", 75);  // Missing 'old' parameter
}

Error Message:

Error[E303]: Signal parameter count mismatch
  Signal 'health_changed' expects 2 parameters, but 1 provided
  |
4 |     emit_signal("health_changed", 75);
  |                 ^^^^^^^^^^^^^^^^^^^^^^ Expected 2 arguments

How to Fix:

Related Codes: E301, E302, E304


E304: Signal Parameter Type Mismatch

Description: An argument provided to emit_signal doesn’t match the expected parameter type.

Common Causes:

Example:

signal score_updated(score: i32);

fn add_score() {
    emit_signal("score_updated", "100");  // String instead of i32
}

Error Message:

Error[E304]: Signal parameter type mismatch
  Signal 'score_updated' parameter 1 expects i32, but String provided
  |
4 |     emit_signal("score_updated", "100");
  |                                  ^^^^^ Expected i32, found String

How to Fix:

Related Codes: E301, E302, E303, E200


Runtime Errors (E400-E499)

Errors that occur during program execution.

E400: Cannot Assign to Immutable Variable

Description: Attempting to assign to a variable that wasn’t declared as mutable.

Common Causes:

Example:

let x = 5;
x = 10;  // 'x' is immutable

Error Message:

Error[E400]: Cannot assign to immutable variable 'x'

How to Fix:

See Also: E405

Related Codes: E405


E401: Undefined Variable

Description: Runtime reference to a variable that doesn’t exist.

Common Causes:

Example:

fn test() {
    print(undefined_var);  // Variable not defined
}

Error Message:

Error[E401]: Undefined variable: undefined_var

How to Fix:

See Also: E201 (compile-time version)

Related Codes: E201


E402: Unknown Built-in Function

Description: Calling a built-in function that doesn’t exist.

Common Causes:

Example:

fn main() {
    println("Hello");  // 'println' doesn't exist, use 'print'
}

Error Message:

Error[E402]: Unknown built-in function: println

How to Fix:

Related Codes: E202, E415


E403: Invalid Assignment Target

Description: Attempting to assign to something that can’t be assigned to.

Common Causes:

Example:

fn test() {
    5 = x;  // Can't assign to literal
}

Error Message:

Error[E403]: Invalid assignment target

How to Fix:

Related Codes: None


E404: Cannot Set Self Properties (No Setter)

Description: Attempting to set a property on self when no property setter is registered.

Common Causes:

Example:

fn _ready() {
    self.position = Vector2 { x: 0.0, y: 0.0 };
}

Error Message:

Error[E404]: Cannot set self properties: no property setter registered

How to Fix:

Related Codes: E410, E417


E405: Cannot Assign to Field of Immutable Variable

Description: Attempting to modify a field of an immutable variable.

Common Causes:

Example:

let vec = Vector2 { x: 1.0, y: 2.0 };
vec.x = 5.0;  // 'vec' is immutable

Error Message:

Error[E405]: Cannot assign to field of immutable variable 'vec'

How to Fix:

Related Codes: E400


E406: Cannot Assign Value to Vector2 Field

Description: Attempting to assign an incompatible value to a Vector2 field.

Common Causes:

Example:

let mut vec = Vector2 { x: 1.0, y: 2.0 };
vec.x = "hello";  // Can't assign String to float field

Error Message:

Error[E406]: Cannot assign String to Vector2.x

How to Fix:

Related Codes: E200, E407


E407: Vector2 Has No Field

Description: Attempting to access a field that doesn’t exist on Vector2.

Common Causes:

Example:

let vec = Vector2 { x: 1.0, y: 2.0 };
let z = vec.z;  // Vector2 only has x and y

Error Message:

Error[E407]: Vector2 has no field 'z'

How to Fix:

See Also: E215 (compile-time version), E406

Related Codes: E215


E408: Cannot Access Field on Non-Object

Description: Attempting to access a field on a value that doesn’t support fields.

Common Causes:

Example:

let x = 42;
let y = x.field;  // i32 doesn't have fields

Error Message:

Error[E408]: Cannot access field 'field' on i32

How to Fix:

Related Codes: E209


E409: Property Is Not a Vector2

Description: Expected a Vector2 property but got a different type.

Common Causes:

Example:

fn _process(delta: f32) {
    self.name.x = 5.0;  // 'name' is String, not Vector2
}

Error Message:

Error[E409]: Property 'name' is not a Vector2

How to Fix:

Related Codes: E200


E410: Cannot Get Self Properties (No Getter)

Description: Attempting to get a property from self when no property getter is registered.

Common Causes:

Example:

fn test() {
    let pos = self.position;
}

Error Message:

Error[E410]: Cannot get self properties: no property getter registered

How to Fix:

Related Codes: E404, E417


E411: Nested Field Assignment Not Yet Implemented

Description: Nested field assignments on regular variables are not yet supported.

Common Causes:

Example:

let mut obj = ...;
obj.field.subfield = value;  // Not yet supported

Error Message:

Error[E411]: Nested field assignment on regular variables not yet implemented

How to Fix:

Related Codes: E412


E412: Complex Field Assignment Not Yet Implemented

Description: Complex field assignment patterns are not yet supported.

Common Causes:

Example:

complex_expression().field = value;

Error Message:

Error[E412]: Complex field assignment not yet implemented

How to Fix:

Related Codes: E411


E413: Division by Zero

Description: Attempting to divide by zero.

Common Causes:

Example:

let x = 10 / 0;  // Division by zero

Error Message:

Error[E413]: Division by zero

How to Fix:

Related Codes: None


E414: Cannot Negate Non-Numeric Value

Description: Attempting to use unary negation on a non-numeric type.

Common Causes:

Example:

let x = -"hello";  // Can't negate String

Error Message:

Error[E414]: Cannot negate non-numeric value

How to Fix:

Related Codes: E213


E415: Undefined Function

Description: Runtime call to a function that doesn’t exist.

Common Causes:

Example:

fn main() {
    call_function("undefined_func", []);
}

Error Message:

Error[E415]: Undefined function: undefined_func

How to Fix:

Related Codes: E202, E402


E416: Wrong Number of Arguments

Description: Runtime function call with wrong number of arguments.

Common Causes:

Example:

fn add(a: i32, b: i32) -> i32 { return a + b; }

fn main() {
    let result = add(5, 10, 15);  // Too many arguments
}

Error Message:

Error[E416]: Function 'add' expects 2 arguments, got 3

How to Fix:

Related Codes: E204


E417: Cannot Access Self Properties (No Property Getter)

Description: Attempting to access self properties when no property getter is registered.

Common Causes:

Example:

fn test() {
    let pos = self.position;
}

Error Message:

Error[E417]: Cannot access self properties: no property getter registered

How to Fix:

Related Codes: E404, E410


E418: Assignment Expressions Should Be Statements

Description: Assignment used as an expression in invalid context.

Common Causes:

Example:

let x = (y = 5);  // Assignment as expression

Error Message:

Error[E418]: Assignment expressions should be statements

How to Fix:

Related Codes: None


E501: emit_signal Requires Signal Name

Description: emit_signal was called without providing a signal name as the first argument.

Common Causes:

Example:

fn trigger_event() {
    emit_signal();  // Missing signal name
}

Error Message:

Error[E501]: emit_signal requires at least a signal name

How to Fix:

Correct Usage:

emit_signal("player_died");
emit_signal("health_changed", 100, 75);

Related Codes: E502, E302, E303


E502: emit_signal Signal Name Must Be String

Description: The first argument to emit_signal must be a string literal containing the signal name.

Common Causes:

Example:

fn trigger_event() {
    emit_signal(123, 456);  // First argument must be string
}

Error Message:

Error[E502]: emit_signal first argument must be a string

How to Fix:

Correct Usage:

emit_signal("score_updated", 100);
emit_signal("player_died");

Related Codes: E501, E302


Getting More Help

If you encounter an error code not listed here or need additional help:

  1. Check the FerrisScript Documentation
  2. Review the FAQ
  3. Search for issues on GitHub Issues
  4. Ask in the community discussions

Contributing

Found an error code that’s unclear or missing information? Please submit a PR to improve this documentation!