nikivdev/code · error · anyhow::Error
Route already exists: {} -> {}. Use --replace to update.
Error message
Route already exists: {} -> {}. Use --replace to update. What it means
run_add adds a host->target route to the local domains proxy config. If the host already maps to a different target and --replace was not passed, the command refuses to silently overwrite the existing mapping and bails with this message.
Source
Thrown at src/domains.rs:189
println!("http://{host}");
}
Ok(())
}
fn run_add(paths: &DomainsPaths, opts: DomainsAddOpts, engine: DomainsEngine) -> Result<()> {
ensure_layout(paths)?;
let host = normalize_host(&opts.host)?;
let target = normalize_target(&opts.target)?;
let mut routes = load_routes(paths)?;
if let Some(existing) = routes.get(&host) {
if existing == &target {
println!("Route already exists: {host} -> {target}");
maybe_reload_running_proxy(paths, engine)?;
return Ok(());
}
if !opts.replace {
bail!(
"Route already exists: {} -> {}. Use --replace to update.",
host,
existing
);
}
}
routes.insert(host.clone(), target.clone());
save_routes(paths, &routes)?;
write_route_files(paths, &routes)?;
maybe_reload_running_proxy(paths, engine)?;
println!("Added route: {host} -> {target}");
Ok(())
}
fn run_rm(paths: &DomainsPaths, opts: DomainsRmOpts, engine: DomainsEngine) -> Result<()> {
ensure_layout(paths)?;
let host = normalize_host(&opts.host)?;View on GitHub (pinned to a747e741ae)
Solutions
- Re-run with --replace to intentionally overwrite the existing route
- Remove the old route first with the rm subcommand, then add the new one
- Inspect the current routes (get/list) to confirm the existing target is stale
Example fix
// before f domains add app.localhost :5173 // error: Route already exists: app.localhost -> :3000. Use --replace to update. // after f domains add app.localhost :5173 --replace
Defensive patterns
Strategy: try-catch
Validate before calling
let routes = load_routes(&paths)?;
let host = normalize_host(&opts.host)?;
if let Some(existing) = routes.get(&host) {
if existing != &opts.target && !opts.replace {
eprintln!("Route exists: {host} -> {existing}; pass --replace to overwrite");
}
} Try / catch
match result {
Err(e) if e.to_string().starts_with("Route already exists:") => {
eprintln!("Re-run with --replace to update the existing route.");
}
other => other?,
} Prevention
- List current routes before adding
- Use --replace intentionally when re-pointing a host
- Prefer the idempotent path: the tool no-ops (OK) when the route already matches
When it happens
Trigger: `domains add <host> <target>` (or `f domains add`) where the routes file already contains the host pointing to a different target and opts.replace is false.
Common situations: Re-pointing a dev hostname to a new port/service, running an add script twice with a changed target, or forgetting that the route file persisted from a previous session.
Related errors
- Session name '{}' already exists. Use a different name or re
- Refusing to overwrite {}
- Route not found: {}
- Host is empty
- Host must be a hostname like linsa.localhost
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/2ca32721bd2938ad.
Report an issue: GitHub.