{"record":{"id":"451aa98d98a23254","repo":"cross-rs/cross","slug":"unknown-container-state-got-state","errorCode":null,"errorMessage":"unknown container state: got {state}","messagePattern":"unknown container state: got (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/docker/shared.rs","lineNumber":479,"sourceCode":"    Running,\n    Paused,\n    Restarting,\n    Dead,\n    Exited,\n    DoesNotExist,\n}\n\nimpl ContainerState {\n    pub fn new(state: &str) -> Result<Self> {\n        match state {\n            \"created\" => Ok(ContainerState::Created),\n            \"running\" => Ok(ContainerState::Running),\n            \"paused\" => Ok(ContainerState::Paused),\n            \"restarting\" => Ok(ContainerState::Restarting),\n            \"dead\" => Ok(ContainerState::Dead),\n            \"exited\" => Ok(ContainerState::Exited),\n            \"\" => Ok(ContainerState::DoesNotExist),\n            _ => eyre::bail!(\"unknown container state: got {state}\"),\n        }\n    }\n\n    #[must_use]\n    pub fn is_stopped(&self) -> bool {\n        matches!(self, Self::Exited | Self::DoesNotExist)\n    }\n\n    #[must_use]\n    pub fn exists(&self) -> bool {\n        !matches!(self, Self::DoesNotExist)\n    }\n}\n\n// the mount directory for the data volume.\npub const MOUNT_PREFIX: &str = \"/cross\";\n// the prefix used when naming volumes\npub const VOLUME_PREFIX: &str = \"cross-\";","sourceCodeStart":461,"sourceCodeEnd":497,"githubUrl":"https://github.com/cross-rs/cross/blob/8c1a8aa4b661711f4b7b6ac07c2e8929ce2f7d27/src/docker/shared.rs#L461-L497","documentation":"`ContainerState::new` maps Docker's Status field strings onto the ContainerState enum. Recognized values are running, paused, restarting, dead, exited, and empty (does not exist). Any other string is rejected, guarding against unexpected daemon output or API changes.","triggerScenarios":"Calling `ContainerState::new` with a status string outside Docker's documented set — e.g. a truncated/renamed status from `docker inspect`/`docker ps --format`, custom formatting, or a newer Docker daemon emitting a new state.","commonSituations":"Parsing `docker ps` output with a custom --format that yields unexpected text, whitespace/case mismatches (\"Running\" vs \"running\"), or a Docker/Podman version difference in status strings.","solutions":["Check the exact status string produced by the container engine (`docker inspect -f '{{.State.Status}}' <id>`).","Trim whitespace and lowercase the status before passing it in.","Confirm the engine is Docker-compatible and its status vocabulary matches what's expected; update the parser mapping if a new state was introduced."],"exampleFix":"// before\nlet state = ContainerState::new(\"Created\")? // fails: unknown\n// after\nlet state = ContainerState::new(\"created\")? // if supported upstream, or use documented states like \"running\"","handlingStrategy":"validation","validationCode":"const STATES: [&str; 6] = [\"running\", \"paused\", \"restarting\", \"dead\", \"exited\", \"\"];\nlet s = status.trim().to_lowercase();\nif !STATES.contains(&s.as_str()) {\n    eprintln!(\"warning: unrecognized container status {status:?}\");\n}","typeGuard":"fn is_known_state(s: &str) -> bool {\n    matches!(s.trim().to_lowercase().as_str(), \"running\" | \"paused\" | \"restarting\" | \"dead\" | \"exited\" | \"\")\n}","tryCatchPattern":null,"preventionTips":["Take status strings directly from a stable source like `docker inspect -f '{{.State.Status}}'`.","Trim and lowercase engine output before constructing ContainerState.","Log unrecognized statuses instead of silently ignoring them so parser drift is caught."],"tags":["docker","container-state","parsing","enum"],"backgroundTag":"invalid-enum-value","analyzedSha":"8c1a8aa4b661711f4b7b6ac07c2e8929ce2f7d27","analyzedAt":"2026-09-13T15:10:43.988Z","contentChangedAt":"2026-09-13T15:10:43.988Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}