nikivdev/code · error

moon build output directory missing: {}

Error message

moon build output directory missing: {}

What it means

Raised by find_built_binary (called from build_task_cached) in src/ai_tasks.rs when the expected moon build output directory `<workspace>/_build/native/release/build` does not exist. This means moon build either never ran successfully or wrote output elsewhere.

Source

Thrown at src/ai_tasks.rs:591

    }
    if version.is_empty() {
        return None;
    }
    if let Some(parent) = cache_file.parent() {
        let _ = fs::create_dir_all(parent);
    }
    let _ = fs::write(&cache_file, format!("{version}\n"));
    Some(version.into_bytes())
}

fn find_built_binary(workspace_dir: &Path) -> Result<PathBuf> {
    let build_dir = workspace_dir
        .join("_build")
        .join("native")
        .join("release")
        .join("build");
    if !build_dir.exists() {
        bail!(
            "moon build output directory missing: {}",
            build_dir.display()
        );
    }

    if let Some(name) = moon_mod_package_name(workspace_dir)? {
        let candidates = [
            build_dir.join(format!("{name}.exe")),
            build_dir.join(name.clone()),
        ];
        for candidate in candidates {
            if candidate.is_file() {
                return Ok(candidate);
            }
        }
    }

    let mut fallback = None;

View on GitHub (pinned to a747e741ae)

Solutions

  1. Run `moon build` (release/native target) in the workspace first, then retry
  2. Check that _build/native/release/build exists after building; adjust the moon build flags to produce a native release build
  3. Clean stale state (remove _build) and rebuild if a moon version change altered the layout

Example fix

// before
// assuming binary exists right after build
let artifact = build_task_cached(task, root, false)?;
// after
run_moon_build(root)?; // ensure `moon build` completed with release/native output
assert!(root.join("_build/native/release/build").exists());
let artifact = build_task_cached(task, root, false)?;
Defensive patterns

Strategy: validation

Validate before calling

let build_dir = root.join("_build").join("native").join("release").join("build");
if !build_dir.exists() {
    eprintln!("run `moon build` first; {} missing", build_dir.display());
}

Try / catch

match build_task_cached(task, root, false) {
    Ok(a) => Ok(a),
    Err(e) if e.to_string().contains("moon build output directory missing") => {
        // trigger a build then retry once
        run_moon_build(root)?;
        build_task_cached(task, root, true)
    }
    Err(e) => Err(e),
}

Prevention

When it happens

Trigger: build_task_cached reports a successful moon build (or skips it) but find_built_binary cannot find the _build/native/release/build directory — e.g. build ran in debug mode, a different backend, or a cleaned workspace.

Common situations: moon built with a different profile/backend so the release/native path differs; _build deleted after build; running on a platform where moon emits a different layout; version changes in moon output paths.

Related errors


AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01). Data as JSON: /api/errors/f5929947e14bafe8. Report an issue: GitHub.