{"record":{"id":"2ca32721bd2938ad","repo":"nikivdev/code","slug":"route-already-exists-use-replace-to-u","errorCode":null,"errorMessage":"Route already exists: {} -> {}. Use --replace to update.","messagePattern":"Route already exists: (.+?) -> (.+?)\\. Use --replace to update\\.","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/domains.rs","lineNumber":189,"sourceCode":"        println!(\"http://{host}\");\n    }\n    Ok(())\n}\n\nfn run_add(paths: &DomainsPaths, opts: DomainsAddOpts, engine: DomainsEngine) -> Result<()> {\n    ensure_layout(paths)?;\n    let host = normalize_host(&opts.host)?;\n    let target = normalize_target(&opts.target)?;\n\n    let mut routes = load_routes(paths)?;\n    if let Some(existing) = routes.get(&host) {\n        if existing == &target {\n            println!(\"Route already exists: {host} -> {target}\");\n            maybe_reload_running_proxy(paths, engine)?;\n            return Ok(());\n        }\n        if !opts.replace {\n            bail!(\n                \"Route already exists: {} -> {}. Use --replace to update.\",\n                host,\n                existing\n            );\n        }\n    }\n\n    routes.insert(host.clone(), target.clone());\n    save_routes(paths, &routes)?;\n    write_route_files(paths, &routes)?;\n    maybe_reload_running_proxy(paths, engine)?;\n    println!(\"Added route: {host} -> {target}\");\n    Ok(())\n}\n\nfn run_rm(paths: &DomainsPaths, opts: DomainsRmOpts, engine: DomainsEngine) -> Result<()> {\n    ensure_layout(paths)?;\n    let host = normalize_host(&opts.host)?;","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/domains.rs#L171-L207","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","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"],"exampleFix":"// before\nf domains add app.localhost :5173\n// error: Route already exists: app.localhost -> :3000. Use --replace to update.\n// after\nf domains add app.localhost :5173 --replace","handlingStrategy":"try-catch","validationCode":"let routes = load_routes(&paths)?;\nlet host = normalize_host(&opts.host)?;\nif let Some(existing) = routes.get(&host) {\n    if existing != &opts.target && !opts.replace {\n        eprintln!(\"Route exists: {host} -> {existing}; pass --replace to overwrite\");\n    }\n}","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().starts_with(\"Route already exists:\") => {\n        eprintln!(\"Re-run with --replace to update the existing route.\");\n    }\n    other => other?,\n}","preventionTips":["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"],"tags":["conflict","duplicate","domains","cli-flag"],"backgroundTag":"resource-already-exists","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}