Skip to main content
Learn how to debug Leo programs, interpret error messages, and resolve common issues during development.

Error Messages

Leo provides structured error messages with unique error codes to help diagnose issues quickly.

Error Code Format

Leo errors follow the format: E{PREFIX}037{CODE}
  • Prefix: Indicates the error category
  • 037: Fixed identifier for Leo errors
  • Code: Unique error number within the category
Example: EPAR0370042 is parser error 42

Error Categories

Leo errors are organized by compiler component:
Errors during source code parsing:
Common causes:
  • Syntax errors
  • Invalid token sequences
  • Missing semicolons or braces
Errors in abstract syntax tree construction:
Common causes:
  • Type mismatches
  • Invalid type annotations
  • Malformed AST nodes
Errors during compilation:
Common causes:
  • Type checking failures
  • Undefined variables
  • Invalid operations
Errors related to project structure and dependencies:
Common causes:
  • Missing program.json
  • Invalid manifest format
  • Dependency resolution failures

Understanding Error Output

Leo error messages include:
  1. Error code: Unique identifier for the error type
  2. Error message: Human-readable description
  3. Source location: File, line, and column
  4. Code snippet: Context showing where the error occurred
  5. Help text: Suggestions for fixing the issue (when available)
Error codes never change once released. You can search for error codes in documentation or online for detailed explanations.

Debugging Techniques

Using Console Output

Leo supports console functions for debugging (development only):
Console functions are removed during production compilation and should only be used for debugging.

Type Checking

Explicitly specify types to catch errors early:

Assertions for Debugging

Use assertions to validate assumptions:

Incremental Testing

Break complex functions into testable parts:

Common Issues

Type Mismatch Errors

1

Problem

2

Cause

Mixing different integer types without explicit conversion:
3

Solution

Ensure type consistency:

Undefined Variable

1

Problem

2

Cause

Using a variable before declaration:
3

Solution

Declare variables before use:

Invalid Program Name

1

Problem

2

Cause

Program name violates naming rules:
  • Starts with underscore or number
  • Contains invalid characters
  • Contains the word “aleo” in the name
3

Solution

Follow naming conventions:

Circular Dependency

1

Problem

2

Cause

Programs importing each other:
3

Solution

Restructure dependencies to be acyclic:

Mapping Access Outside Finalize

1

Problem

2

Cause

Trying to use Mapping::get or Mapping::set in a regular function:
3

Solution

Access mappings only in finalize functions:

Build and Compilation Issues

Check Syntax

Run syntax validation without full compilation:

Clean Build

Remove build artifacts and rebuild:

Verbose Output

Enable detailed compiler output:

Compiler Version

Verify you’re using the correct Leo version:
Update if needed:

Development Workflow

1

Write Code

Implement your feature with explicit types and comments:
2

Check Syntax

Validate syntax before testing:
3

Run Tests

Execute tests to verify behavior:
4

Debug Failures

If tests fail, add debug output:
5

Build for Production

Compile the final program:

Rust-level Debugging

For compiler development, use Rust debugging tools:

Running Tests with Output

Using Clippy

Run the linter to catch common issues:

Format Checking

Ensure code is properly formatted:
Leo uses nightly Rust formatter. Install with:

Performance Debugging

Circuit Size

Monitor generated circuit size:

Loop Unrolling

Be aware of loop unrolling impact:
Excessive loop unrolling increases circuit size dramatically. Keep iteration counts reasonable.

Memory Usage

From the compiler’s performance guidelines:
  • Pre-allocate collections with with_capacity when size is known
  • Avoid unnecessary clones
  • Use references when ownership isn’t needed
  • Minimize intermediate allocations

Getting Help

Search Error Codes

Look up error codes in documentation:

Community Resources

Filing Bug Reports

When filing issues, include:
  1. Leo version (leo --version)
  2. Minimal reproducible example
  3. Full error message with code
  4. Expected vs actual behavior
  5. Operating system
Provide a minimal test case that reproduces the issue. This helps maintainers diagnose and fix problems faster.

Next Steps