{"record":{"id":"d860825524e587e5","repo":"jdx/mise","slug":"cannot-remove-user-service-name","errorCode":null,"errorMessage":"cannot remove user service '{name}': {}","messagePattern":"cannot remove user service '(.+?)': (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/user_services.rs","lineNumber":659,"sourceCode":"        return Ok(());\n    }\n    if cfg!(target_os = \"linux\") {\n        systemd::apply(&[request.systemd_request()?], dry_run).await\n    } else if cfg!(target_os = \"macos\") {\n        launchd::apply(&[request.launchd_request()?], dry_run).await\n    } else {\n        scheduled_tasks::apply(&[request.scheduled_task_request()], dry_run).await\n    }\n}\n\n/// Remove the installed definition for `name`, declared or not. Returns\n/// whether one existed.\npub(crate) async fn remove_named(name: &str, dry_run: bool) -> Result<bool> {\n    if !valid_name(name) {\n        bail!(\"user service name '{name}' must contain only letters, numbers, '.', '_', or '-'\");\n    }\n    if !is_available() {\n        bail!(\n            \"cannot remove user service '{name}': {}\",\n            unavailable_reason()\n        );\n    }\n    if cfg!(target_os = \"linux\") {\n        systemd::remove_service(name, dry_run).await\n    } else if cfg!(target_os = \"macos\") {\n        launchd::remove_agent(name, dry_run).await\n    } else {\n        scheduled_tasks::remove_task(name, dry_run).await\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n    use crate::system::services_common::ServiceScope;\n","sourceCodeStart":641,"sourceCodeEnd":677,"githubUrl":"https://github.com/jdx/mise/blob/afd2eddd3a50c16190efc1c7e94404b48f72af57/src/system/user_services.rs#L641-L677","documentation":"Removing a user service requires a supported service manager on the platform (systemd on Linux, launchd on macOS). If `is_available()` reports the manager is unavailable, `remove_named` fails with the reason from `unavailable_reason()`.","triggerScenarios":"`remove_named` called (via `apply_one`) on a system where the expected user-service manager is missing/unusable, e.g. Linux without systemd (containers, WSL1, non-systemd distros) or macOS where launchd access fails (src/system/user_services.rs:659).","commonSituations":"Running bootstrap service management inside Docker containers without systemd; minimal/CI environments without a user session bus (`systemctl --user` unavailable); non-systemd init distros.","solutions":["Run on a system with systemd (Linux) or launchd (macOS) available","Ensure a user session/systemd user instance is running (`systemctl --user status` works)","Skip or gate user services in containers/CI config","Read `unavailable_reason()` in the message for the specific cause"],"exampleFix":"null","handlingStrategy":"try-catch","validationCode":"// Precheck (Linux): systemctl --user works?\n// systemctl --user status >/dev/null 2>&1 || echo \"systemd user session unavailable\"","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().starts_with(\"cannot remove user service\") => {\n        // log unavailable_reason() and skip user-service management on this host\n    }\n    other => other?,\n}","preventionTips":["Gate user-service config behind host capability detection (systemd/launchd present)","Skip service management in containers and CI without a user session","Read the unavailable_reason() text in the error to diagnose the environment"],"tags":["platform","systemd","launchd","environment","user-services"],"backgroundTag":"unsupported-platform","analyzedSha":"afd2eddd3a50c16190efc1c7e94404b48f72af57","analyzedAt":"2026-09-09T01:38:25.179Z","contentChangedAt":"2026-09-09T01:38:25.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}