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

MGS1022: member only callable from a magusfile

A spell or a magus buzz script called a magus\* member that only a magusfile can serve.

[MGS1022] magus\project: only callable from a magusfile, not from a spell or a
  `magus buzz` script - it declares into the workspace magus is loading, and
  neither has one

import "magus" resolves everywhere Buzz runs, and most of the namespace works in a script or a spell. Two groups do not, for two different reasons.

Members that declare into a workspace

magus\project, magus\cache.remote, and magus\ci.provider record onto the registry magus builds while it loads a workspace. Evaluating a magusfile creates that registry. Nothing loads a script into a workspace, and a spell is loaded WHILE one is still being built, so a declaration made in either has nowhere to land.

There is no script-side equivalent, because there is nothing to declare. Put the declaration in the magusfile.buzz of the project it describes.

Members that read a loaded workspace

magus\describe.project, magus\affected, magus\graph, and magus\where answer from the workspace already open on the context, which is what makes them free of a subprocess. A script has no workspace open, and a spell runs before the one being loaded exists.

These do have an equivalent that works in both: the members that run a nested magus, which discovers the workspace root itself. From a spell, this is the only option; see authoring spells.

import "std";
import "magus";

fun main() > void !> any {
    // magus\describe.project() raises MGS1022 here; evaluatedProject forks and does not.
    foreach (p in magus\describe.evaluatedProject()) {
        std\print(p.path);
    }
}
main();

magus\cmd, magus\run, magus\insight, magus\doctor and the magus\describe methods that fork all work this way, and so does the rest of the namespace: magus\normalize, magus\describe.module, and the log levels (magus\info/debug/warn/error).

Resolution

Which fix applies depends on which group the member falls in.

A member that declares (magus\project, magus\cache.remote, magus\ci.provider) has no script-side equivalent, because there is nothing to declare. Move the call into the magusfile.buzz of the project it describes.

A member that reads a loaded workspace (magus\projects, magus\targets, magus\affected, magus\graph, magus\where) swaps for the member that runs a nested magus and finds the workspace root itself: magus\describe, magus\cmd, magus\run, magus\insight, magus\doctor. The example above is that substitution for magus\projects.

Why the import resolves at all

import "magus" used to fail outright in a script. You would read that as "there is no such module" and go looking for one that does not exist. Failing at the member instead names the rule you hit and leaves the rest of the namespace reachable, the way vcs\isDirty raises when no VCS is resolved while the vcs module stays where it is.

See also

  • magus module: every member, and what each one needs.
  • Debugging: the REPL, which does load a magusfile (magus buzz with no arguments).
MGS1022magusfilebuzzscriptsnamespace
Last updated (29d8b3de)
Earlier changes on this page (7)

Full history ↗ · Blame source ↗

Glossary

Workspace

The magus root directory that owns a set of projects and shared config; the unit magus operates over. Workspace in full.

Project

A directory magus recognizes as a unit of work (it has a magusfile); the unit of caching, scheduling, and dependency tracking. Project in full.

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.

Module

A magus stdlib namespace a magusfile imports for host capabilities: filesystem, exec, vcs, and more. Module in full.

Buzz

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

Cache

The content-addressed store magus consults before running a target, so unchanged work is skipped. Cache in full.

Affected

The set of projects touched by a change; magus affected <target> runs a target only over them. Affected in full.

CI

An ordinary target you compose yourself with ctx.needs; magus does not hardcode its stages. It is the anchor magus affected ci keys off, and ci strips the rw charm. CI in full.

MAGUS.md

The committed routing index at a workspace root, regenerated from the knowledge graph: it lists every node and points at the exact query for a given question, so it is the entry point an agent reads first. MAGUS.md in full.

Insight

The reports magus derives over the graph and history (hotspots, affinity, ownership, trend, volatility, unreferenced). Insight in full.

Run

One target executing under one magus invocation, such as magus run test web or magus affected ci. A run keeps its captured output behind an output reference. Every magus run is a run whether or not any job asked for it; see Job for how the two relate. Run in full.

Conventions

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