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
EPAR0370042 is parser error 42
Error Categories
Leo errors are organized by compiler component:Parser Errors (PAR: 0-999)
Parser Errors (PAR: 0-999)
Errors during source code parsing:Common causes:
- Syntax errors
- Invalid token sequences
- Missing semicolons or braces
AST Errors (AST: 2000-2999)
AST Errors (AST: 2000-2999)
Errors in abstract syntax tree construction:Common causes:
- Type mismatches
- Invalid type annotations
- Malformed AST nodes
Compiler Errors (CMP: 6000-6999)
Compiler Errors (CMP: 6000-6999)
Errors during compilation:Common causes:
- Type checking failures
- Undefined variables
- Invalid operations
Package Errors (PAK: 5000-5999)
Package Errors (PAK: 5000-5999)
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:- Error code: Unique identifier for the error type
- Error message: Human-readable description
- Source location: File, line, and column
- Code snippet: Context showing where the error occurred
- Help text: Suggestions for fixing the issue (when available)
Debugging Techniques
Using Console Output
Leo supports console functions for debugging (development only):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: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:Memory Usage
From the compiler’s performance guidelines:- Pre-allocate collections with
with_capacitywhen 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
- Discord: discord.gg/aleo
- GitHub Issues: github.com/ProvableHQ/leo/issues
- Forum: forum.aleo.org
Filing Bug Reports
When filing issues, include:- Leo version (
leo --version) - Minimal reproducible example
- Full error message with code
- Expected vs actual behavior
- Operating system
Next Steps
- Learn about package management to handle dependencies
- Review best practices for writing robust code
- Explore testing strategies for comprehensive coverage