Error Handling
MIND provides comprehensive error diagnostics with detailed messages, source locations, and actionable suggestions.
Error Categories
| Category | Code | Description |
|---|---|---|
| Parse | E0001-E0099 | Syntax errors |
| Type | E0100-E0199 | Type mismatches, inference failures |
| Shape | E0200-E0299 | Dimension mismatches, broadcast failures |
| Autodiff | E0300-E0399 | Non-differentiable operations |
| Device | E0400-E0499 | Placement and transfer errors |
| Runtime | E0500-E0599 | Execution errors |
Example Diagnostics
Shape mismatch error:
error[E0201]: shape mismatch in matmul --> model.mind:12:15 | 12 | let y = a @ b; | ^ cannot multiply tensors with shapes [2, 3] and [4, 5] | = help: matmul requires inner dimensions to match = note: expected shape [2, 3] @ [3, ?], got [2, 3] @ [4, 5]
Type error with suggestion:
error[E0102]: type mismatch --> train.mind:8:20 | 8 | let loss: i32 = mse(pred, target); | --- ^^^^^^^^^^^^^^^^^ | | expected i32, found f32 | expected due to this | = help: consider changing the type annotation | 8 | let loss: f32 = mse(pred, target); | ~~~
Runtime Errors
Runtime errors occur during execution and include stack traces:
runtime error[E0501]: index out of bounds --> inference.mind:24:10 | 24 | x[i] | ^^^^ index 10 is out of bounds for tensor of length 5 | stack trace: 0: get_element at inference.mind:24:10 1: process_batch at inference.mind:18:5 2: main at inference.mind:5:3
Result Type
For recoverable errors, use the Result type:
fn load_model(path: str) -> Result<Model, Error> {
if !exists(path) {
return Err(Error::NotFound(path));
}
// ...
Ok(model)
}
fn main() {
match load_model("model.mind.bin") {
Ok(model) => run(model),
Err(e) => print("Failed to load: ", e),
}
}Learn More
See the full error catalog at mind-spec/errors.md.