magus v0.4.3 is out. See what's new
¶ View markdown source · ✎ Suggest an edit
1 min read

MGS1051: a spell does not match the spell contract

magus refuses to load a spell when one of its exported mgs_ functions does not match the spell contract:

  • it declares a return type other than the contract's, > any included;
  • it declares no return type;
  • it takes parameters;
  • its name is not a contract function, such as a misspelling or a function the contract no longer has.

magus reads each function's return annotation from the spell's source before it calls any of them, on every load. The error lists every violation with its line.

Why

magus decodes each mgs_ value into the type the contract names. The Buzz checker checks a function body against its own annotation, but nothing else checks that annotation against the contract, so a spell declaring > any hands magus a value whose shape nothing checked. A function the contract does not list is a declaration magus would silently ignore.

Resolution

  • Declare the contract's return type. The spell contract lists each function's exact annotation, for example export fun mgs_getLanguage() > Language.
  • Return one shape per function. A > any that mixes commands and services splits into mgs_listTargets and mgs_listServices.
  • Rename or remove an unknown function. Fix a misspelling; delete a function the contract dropped.
MGS1051magusfilespellscontractmgs_
Last updated (73992e6a)
Earlier changes on this page (1)

Full history ↗ · Blame source ↗

Glossary

Magusfile

The magusfile.buzz that declares a project's targets (as export funs) and binds its spells. Magusfile in full.

Target

A named operation (build, test, ...) you invoke with magus run <target>; it may compose a spell's tool-native operations and depend on other targets. Target in full.

Op

A single tool-native command a target composes (long form: operation); the middle of the work hierarchy (Spell to Op to Target). Op in full.

Spell

A language/runtime adapter (e.g. go, md) that maps generic targets onto a toolchain's real commands. Spell in full.

Buzz

The language magusfiles are written in (the .buzz engine). Buzz in full.

Service

A long-running or shared process magus manages across runs, distinct from a one-shot target. Service in full.

Conventions

This page uses none of the site's convention markers. The full set is on the conventions page.