nikivdev/code · error

handled before project context load

Error message

handled before project context load

What it means

build_web_ui in src/web.rs builds the bundled web UI whenever .ai/web/package.json exists in the project. Before building it checks that the `bun` executable is on PATH via the `which` crate; if not, it bails with this message. The build deliberately hard-requires bun (it uses bun.lock and bun install), so it fails fast rather than attempting a partial build.

Source

Thrown at src/deploy.rs:417

            lines,
        }) => show_logs(
            &project_root,
            flow_config.as_ref(),
            follow,
            since_deploy,
            all,
            lines,
        ),
        Some(DeployAction::Restart) => restart_service(&project_root, flow_config.as_ref()),
        Some(DeployAction::Stop) => stop_service(&project_root, flow_config.as_ref()),
        Some(DeployAction::Health { url, status }) => {
            check_health(&project_root, flow_config.as_ref(), url, status)
        }
        Some(DeployAction::Config)
        | Some(DeployAction::Release(_))
        | Some(DeployAction::Shell)
        | Some(DeployAction::SetHost { .. })
        | Some(DeployAction::ShowHost) => unreachable!("handled before project context load"),
    }
}

/// Run a production deploy (skips flow.deploy_task and prefers deploy-prod/prod tasks).
pub fn run_prod(cmd: DeployCommand) -> Result<()> {
    match cmd.action {
        Some(DeployAction::Config) => configure_deploy(),
        Some(DeployAction::Release(opts)) => release::run_task(opts),
        Some(DeployAction::Shell) => open_shell(),
        Some(DeployAction::SetHost { connection }) => set_host(&connection),
        Some(DeployAction::ShowHost) => show_host(),
        action => {
            let ctx = load_deploy_project_context()?;
            run_prod_with_project_context(action, ctx)
        }
    }
}

View on GitHub (pinned to a747e741ae)

Solutions

  1. Install bun (curl -fsSL https://bun.sh/install | bash) and ensure ~/.bun/bin is on PATH.
  2. Remove or rename .ai/web/package.json if you do not need the bundled web UI; build_web_ui then skips the build entirely.
  3. Verify with `which bun`; if it prints nothing, fix PATH before running flow.

Example fix

// before (CI without bun)
- run: cargo run -- flow serve
// after
+ run: |
+   curl -fsSL https://bun.sh/install | bash
+   echo "$HOME/.bun/bin" >> "$GITHUB_PATH"
+   cargo run -- flow serve
Defensive patterns

Strategy: validation

Validate before calling

if !std::path::Path::new(".ai/web/package.json").exists() { /* ok: build skipped */ }
else if which::which("bun").is_err() {
    eprintln!("install bun first: curl -fsSL https://bun.sh/install | bash");
}

Type guard

fn bun_available() -> bool { which::which("bun").is_ok() }

Try / catch

match flow::web::build_result {
    Err(e) if e.to_string().contains("bun is required") => install_bun_and_retry(),
    Err(e) => return Err(e),
    Ok(v) => v,
}

Prevention

When it happens

Trigger: Running the flow command whose run() path calls build_web_ui when a project contains .ai/web/package.json but `bun` is not installed or not on PATH (e.g. PATH missing ~/.bun/bin, CI image without bun).

Common situations: Fresh machines or Docker images without bun installed; users who cloned a repo that ships a .ai/web frontend but never installed bun; PATH configured for node/npm but not bun; running the tool from an environment (cron, IDE launcher) with a stripped PATH.

Related errors


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