Skip to content

When things go wrong

Every diagnostic points at the source with a caret. These are the ones you will meet most often, each captured from a real run.

The type checker is strict and has no implicit conversions:

Terminal window
error: type mismatch: expected f64, found bool
--> mismatch.mag:2:9
|
2 | y = u > 0.0;
| ^^^^^^^

Often a parameter used without self.. Parameters are read as self.kp, not kp:

Terminal window
error: undefined variable `kp`
--> undef.mag:2:13
|
2 | u_out = kp * e;
| ^^

The caret sits at the end of the statement that needs the ;, not at the token that revealed it:

Terminal window
error: missing `;` before `y`
--> semi.mag:3:28
|
3 | let scaled = self.k * u
| ^

A self. path walks the declared parameter tree and reports the model where the path ran out:

Terminal window
error: unknown parameter `self.motor.omega_init`: model `Motor` has no field `omega_init`
--> path.mag:5:27
|
5 | let prev = self.motor.omega_init fby y;
| ^^^^^^^^^^

The initial value is evaluated before the first tick, so it may use parameters but not signals:

Terminal window
error: `fby` initial value must be a constant or an expression of parameters
--> fbyinit.mag:2:9
|
2 | y = u fby (y + dt * u);
| ^

Every declared instance is stepped exactly once per tick:

Terminal window
error: model instance `self.pid` is never stepped
--> unstepped.mag:3:14
|
3 | model Loop { pid: Pid, }
| ^^^

The first segment of a use path is a dependency from Magnet.toml, core, or crate:

Terminal window
error: unknown module `motors`; the first segment is a `Magnet.toml` dependency (or `core`), or `crate` for a module of this package, and the rest are directories under its `src/`. A hyphenated name is imported with underscores (`control-lib` → `control_lib`)
--> unknown_pkg.mag:1:5
|
1 | use motors::Dc;
| ^^^^^^

magnet simulate runs the one model that no other model instantiates. With several such models, it needs --model:

Terminal window
the package declares several models; pick one with --model: Logger, Plant

A diagnostic is exit code 1: the model is at fault. Code 2 is magnet’s own fault. The table is on the CLI reference.