nikivdev/code · error · anyhow::Error

{} failed

Error message

{} failed

What it means

run_command executes an external command (used by ensure_docs_hub_deps for `bun install` / `npm install`) and bails with "<cmd> failed" when the command runs but exits non-zero. The message intentionally echoes only the program name; the real diagnostics were printed by the child to its own stderr.

Source

Thrown at src/docs.rs:676

            .with_context(|| format!("failed to switch to {}", path.display()))?;
        Ok(Self { previous })
    }
}

impl Drop for DirGuard {
    fn drop(&mut self) {
        let _ = std::env::set_current_dir(&self.previous);
    }
}

fn run_command(cmd: &str, args: &[&str], cwd: &Path) -> Result<()> {
    let status = Command::new(cmd)
        .args(args)
        .current_dir(cwd)
        .status()
        .with_context(|| format!("failed to run {}", cmd))?;
    if !status.success() {
        bail!("{} failed", cmd);
    }
    Ok(())
}

fn attach_pages_domain(hub_root: &Path, project: &str, domain: &str) -> Result<()> {
    println!("Attaching custom domain {domain} to {project}...");
    let mut cmd = if which("bun").is_ok() {
        let mut cmd = Command::new("bun");
        cmd.args(["x", "wrangler", "pages", "domain", "add", project, domain]);
        cmd
    } else if which("npx").is_ok() {
        let mut cmd = Command::new("npx");
        cmd.args(["wrangler", "pages", "domain", "add", project, domain]);
        cmd
    } else if which("npm").is_ok() {
        let mut cmd = Command::new("npm");
        cmd.args([
            "exec", "wrangler", "--", "pages", "domain", "add", project, domain,

View on GitHub (pinned to a747e741ae)

Solutions

  1. Re-run the install manually in the hub root (cd <hub_root> && bun install / npm install) to see the full child error output
  2. Check network/proxy access to the package registry; configure HTTPS_PROXY or registry mirrors if blocked
  3. Delete node_modules and the lockfile (or refresh the lockfile with the installed package manager version) and reinstall
  4. Verify the Node/bun version satisfies the hub's engines requirement and upgrade if needed

Example fix

// before
$ mytool docs hub
Error: bun failed
// after (diagnose directly)
$ cd ~/.config/flow/docs-hub && bun install
error: lockfile had changes, but lockfile is frozen
$ rm -rf node_modules bun.lock && bun install
$ mytool docs hub
Defensive patterns

Strategy: try-catch

Validate before calling

// check registry reachability before install
fn registry_ok() -> bool {
    std::net::TcpStream::connect("registry.npmjs.org:443").is_ok()
}
if !registry_ok() {
    eprintln!("package registry unreachable; check network/proxy before installing");
    return;
}

Try / catch

match run_docs_hub(&opts) {
    Err(e) if e.to_string().ends_with("failed") && e.to_string().contains("bun") => {
        eprintln!("bun install failed; re-run manually in hub root for full error output");
        let _ = std::process::Command::new("bun").arg("install").current_dir(&hub_root).status();
    }
    Err(e) => return Err(e),
    Ok(()) => {}
}

Prevention

When it happens

Trigger: `bun install` or `npm install` exits non-zero in the hub root: network failure reaching the registry, package-lock/lockfile mismatch, unsupported engine version, corrupted cache, or out-of-disk during install.

Common situations: Offline or proxied environments blocking registry.npmjs.org or bun's registry; lockfile generated by a newer npm/bun; private packages requiring an auth token; Node engines mismatch (e.g. package requires Node >=20).

Related errors


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