Skip to content

Latest commit

 

History

History
292 lines (206 loc) · 5.05 KB

File metadata and controls

292 lines (206 loc) · 5.05 KB

Error Codes and Messages

Understanding WFL error messages and how to fix them.

Error Categories

WFL errors fall into 4 categories:

  1. Parse Errors - Syntax problems
  2. Semantic Errors - Invalid program structure
  3. Type Errors - Type mismatches
  4. Runtime Errors - Execution failures

Parse Errors

"Expected identifier, found Keyword..."

Cause: Using reserved keyword as variable name.

Example:

store is as 10  // ERROR: 'is' is reserved

Fix:

store is_valid as 10

Quick lookup → | Complete details →


"Expected 'end' after if block"

Cause: Missing end check.

Example:

check if condition:
    code
// Missing end check!

Fix:

check if condition:
    code
end check

"Unexpected token in expression"

Cause: Invalid syntax.

Example:

display age plus name  // If name is reserved keyword

Fix: Check for reserved keywords, verify syntax.


Semantic Errors

"Variable 'x' is not defined"

Cause: Using variable before declaring.

Example:

display user_name  // Not defined yet

Fix:

store user_name as "Alice"
display user_name

"Action 'foo' is not defined"

Cause: Calling undefined action.

Example:

call greet with "World"  // greet not defined

Fix:

define action called greet with parameters name:
    display "Hello, " with name
end action

call greet with "World"

Type Errors

"Type mismatch: cannot add Number and Text"

Cause: Incompatible types in operation.

Example:

store age as 25
store name as "Alice"
display age plus name  // ERROR

Fix:

display "Name: " with name with ", Age: " with age

"Expected Number, got Text"

Cause: Function expects number, got text.

Example:

store result as abs of "hello"  // ERROR

Fix:

store result as abs of -5  // Numbers only

"Could not infer type for variable"

Cause: Type checker can't determine type (usually arithmetic on untyped action parameters).

Example:

define action called process with parameters x:
    store result as x plus 1  // Type of x unknown
    return result
end action

Fix: This is a warning, not an error — the code still runs. This applies everywhere, including files pulled in with include from (included files are never type-checked more strictly than the main program).

Note: comparison results (a is equal to b), list/object indexing (parts[0], rec["k"]), length of, and builtin call results are all inferable and do not produce this warning.


Runtime Errors

"Division by zero"

Cause: Dividing by zero.

Example:

store result as 10 divided by 0

Fix:

check if divisor is not equal to 0:
    store result as 10 divided by divisor
otherwise:
    display "Cannot divide by zero"
end check

"Index out of bounds"

Cause: Accessing list index that doesn't exist.

Example:

store items as [1, 2, 3]
store item as items[10]  // Only 3 items!

Fix:

check if 10 is less than length of items:
    store item as items[10]
otherwise:
    display "Index too large"
end check

"Cannot pop from empty list"

Cause: Popping when list has no items.

Example:

create list empty
end list
store item as pop of empty  // ERROR

Fix:

check if length of list is greater than 0:
    store item as pop of list
otherwise:
    display "List is empty"
end check

"File not found"

Cause: Opening non-existent file.

Example:

open file at "missing.txt" for reading as myfile

Fix:

try:
    open file at "missing.txt" for reading as myfile
    // ...
catch:
    display "File not found"
end try

"Permission denied"

Cause: Insufficient permissions.

Fix: Check file permissions, run with appropriate privileges.


Error Message Format

WFL error messages include:

[ERROR_TYPE]: Description
   ┌─ file.wfl:line:column
   │
line │ code
   │   ^ Error occurred here

Components:

  • Error type - Parse, semantic, type, runtime
  • Description - What went wrong
  • Location - Exact line and column
  • Context - Code snippet showing error
  • Pointer - Visual indicator

Getting Help

For any error:

  1. Read the error message - WFL provides helpful descriptions
  2. Check line and column - Exact location shown
  3. Look for typos - Common cause of errors
  4. Verify syntax - Use Syntax Reference
  5. Check examples - WFL by Example

Still stuck?


Previous: ← Built-in Functions | Next: Development →