nikivdev/code · error · anyhow::Error
wrangler pages domain add failed
Error message
wrangler pages domain add failed
What it means
After running `wrangler pages domain add <project> <domain>`, attach_pages_domain checks the exit status and bails if wrangler failed. The failure occurred inside wrangler — typically Cloudflare authentication, permissions, or an invalid project/domain — not in this library.
Source
Thrown at src/docs.rs:708
cmd
} else if which("npm").is_ok() {
let mut cmd = Command::new("npm");
cmd.args([
"exec", "wrangler", "--", "pages", "domain", "add", project, domain,
]);
cmd
} else {
bail!("bun, npx, or npm is required to run wrangler");
};
let status = cmd
.current_dir(hub_root)
.stdin(std::process::Stdio::inherit())
.stdout(std::process::Stdio::inherit())
.stderr(std::process::Stdio::inherit())
.status()
.context("failed to run wrangler pages domain add")?;
if !status.success() {
bail!("wrangler pages domain add failed");
}
Ok(())
}
fn prompt_line(message: &str, default: Option<&str>) -> Result<String> {
if let Some(default) = default {
print!("{message} [{default}]: ");
} else {
print!("{message}: ");
}
io::stdout().flush()?;
let mut input = String::new();
io::stdin().read_line(&mut input)?;
let trimmed = input.trim();
if trimmed.is_empty() {
return Ok(default.unwrap_or("").to_string());
}
Ok(trimmed.to_string())View on GitHub (pinned to a747e741ae)
Solutions
- Run the command manually in the hub root to see wrangler's real error: npx wrangler pages domain add <project> <domain>
- Ensure Cloudflare credentials are set (wrangler login or CLOUDFLARE_API_TOKEN with Pages:Edit permission)
- Verify the Pages project name matches an existing deployed project and the domain's zone is in the same Cloudflare account
- Update wrangler (`npm i -g wrangler` or bun equivalent) if the pages subcommand is unsupported
Example fix
// before $ mytool docs hub deploy --domain docs.example.com Error: wrangler pages domain add failed (wrangler: Not logged in) // after $ export CLOUDFLARE_API_TOKEN=cf_... # token with Pages:Edit $ mytool docs hub deploy --domain docs.example.com
Defensive patterns
Strategy: try-catch
Validate before calling
// verify Cloudflare credentials before deploying a custom domain
if std::env::var("CLOUDFLARE_API_TOKEN").is_err() {
eprintln!("CLOUDFLARE_API_TOKEN not set; wrangler domain add will fail");
return;
} Try / catch
match deploy_docs_hub(&opts) {
Err(e) if e.to_string().contains("wrangler pages domain add failed") => {
eprintln!("wrangler failed; run `npx wrangler pages domain add <project> <domain>` manually for the real error (auth? project? zone?)");
}
Err(e) => return Err(e),
Ok(()) => {}
} Prevention
- Set CLOUDFLARE_API_TOKEN (Pages:Edit permission) in deploy environments
- Confirm the Pages project exists and is deployed before attaching domains
- Ensure the custom domain's zone belongs to the same Cloudflare account
- Keep wrangler up to date so `pages domain add` is supported
When it happens
Trigger: Calling deploy_docs_hub with a custom domain when wrangler exits non-zero: not logged in (no CLOUDFLARE_API_TOKEN), token lacking Pages domain permissions, project name wrong or not yet deployed, domain not owned/zone not on the account, or wrangler not resolvable indirectly (npm exec failing).
Common situations: CI deploying with missing/expired CLOUDFLARE_API_TOKEN; typo in project name; custom domain whose DNS zone belongs to another Cloudflare account; wrangler version too old for `pages domain add`.
Related errors
- bun, npx, or npm is required to run wrangler
- codex skill-eval launchd install failed: {}
- failed to stash working tree: {}
- {} failed
- git diff --cached --name-only failed
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/cf4626c8578db477.
Report an issue: GitHub.