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. 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 (aba0c4fa)
Glossary

Magusfile

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

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. See targets.

Op

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

Spell

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

Buzz

The language magusfiles are written in (the .buzz engine). See engines.

Service

A long-running or shared process magus manages across runs, distinct from a one-shot target. See services.

Conventions

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