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

MGS1022: member only callable from a magusfile

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

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

import "magus" resolves everywhere Buzz runs, and most of the namespace works in a script. 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, so a declaration made there 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\ls, magus\targets, 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.

These do have a script-side equivalent: the members that run a nested magus, which discovers the workspace root itself.

import "std";
import "magus";

fun main() > void {
    // magus\ls() raises MGS1022 here; the nested command does not.
    final projects = magus\describe(["projects", "-o", "json"], opts: {"quiet": true});
    std\print(projects.stdout);
}
main();

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

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 actually 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 (843581cb)
Glossary

Workspace

The magus root directory that owns a set of projects and shared config; the unit magus operates over. See workspace.

Project

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

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.

Module

A magus stdlib namespace a magusfile imports for host capabilities: filesystem, exec, vcs, and more. See the module reference.

Buzz

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

Cache

The content-addressed store magus consults before running a target, so unchanged work is skipped. See cache.

Affected

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

CI

An ordinary magusfile-defined target you compose yourself with magus\needs - magus does not hardcode its stages. Magus.RunCI treats it specially only in that it strips the rw charm, it is the anchor magus affected ci keys off, and a selected scope with no project declaring it is a load error rather than a silent no-op. See targets.

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

Insight

The reports magus derives over the graph and history (hotspots, affinity, ownership, trend). See insight.

Conventions

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