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.
Type mismatch
Section titled “Type mismatch”The type checker is strict and has no implicit conversions:
error: type mismatch: expected f64, found bool --> mismatch.mag:2:9 |2 | y = u > 0.0; | ^^^^^^^Undefined variable
Section titled “Undefined variable”Often a parameter used without self.. Parameters are read as self.kp, not kp:
error: undefined variable `kp` --> undef.mag:2:13 |2 | u_out = kp * e; | ^^Missing semicolon
Section titled “Missing semicolon”The caret sits at the end of the statement that needs the ;, not at the token that revealed it:
error: missing `;` before `y` --> semi.mag:3:28 |3 | let scaled = self.k * u | ^Unknown parameter path
Section titled “Unknown parameter path”A self. path walks the declared parameter tree and reports the model where the path ran out:
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; | ^^^^^^^^^^Non-constant fby initial value
Section titled “Non-constant fby initial value”The initial value is evaluated before the first tick, so it may use parameters but not signals:
error: `fby` initial value must be a constant or an expression of parameters --> fbyinit.mag:2:9 |2 | y = u fby (y + dt * u); | ^Unstepped model instance
Section titled “Unstepped model instance”Every declared instance is stepped exactly once per tick:
error: model instance `self.pid` is never stepped --> unstepped.mag:3:14 |3 | model Loop { pid: Pid, } | ^^^Unknown module
Section titled “Unknown module”The first segment of a use path is a dependency from Magnet.toml, core, or crate:
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; | ^^^^^^Ambiguous model
Section titled “Ambiguous model”magnet simulate runs the one model that no other model instantiates. With several such models,
it needs --model:
the package declares several models; pick one with --model: Logger, PlantExit codes
Section titled “Exit codes”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.