{"record":{"id":"1d93fa1ac8fcd854","repo":"jdx/mise","slug":"container-inspection-returned-an-unexpected-number","errorCode":null,"errorMessage":"container inspection returned an unexpected number of rows","messagePattern":"container inspection returned an unexpected number of rows","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/compose.rs","lineNumber":611,"sourceCode":"\n    fn add_container_hashes(&self, containers: &mut [ComposeContainer]) -> Result<()> {\n        if containers.is_empty() {\n            return Ok(());\n        }\n        let ids = containers\n            .iter()\n            .map(|container| container.id.clone())\n            .collect::<Vec<_>>();\n        let mut args = vec![\n            \"inspect\".to_string(),\n            \"--format\".to_string(),\n            \"{{json .Config.Labels}}\".to_string(),\n        ];\n        args.extend(ids);\n        let output = self.engine_output(&args)?;\n        let lines = output.lines().collect::<Vec<_>>();\n        if lines.len() != containers.len() {\n            bail!(\"container inspection returned an unexpected number of rows\");\n        }\n        for (container, line) in containers.iter_mut().zip(lines) {\n            let labels: HashMap<String, String> = serde_json::from_str(line)?;\n            container.config_hash = labels.get(\"com.docker.compose.config-hash\").cloned();\n        }\n        Ok(())\n    }\n\n    fn desired(&self) -> String {\n        match self.state {\n            ComposeState::Running => format!(\n                \"running{}; pull {:?}; build {:?}; recreate {:?}; wait {}\",\n                selected_suffix(&self.services),\n                self.pull,\n                self.build,\n                self.recreate,\n                self.wait\n            )","sourceCodeStart":593,"sourceCodeEnd":629,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/compose.rs#L593-L629","documentation":"Thrown by `add_container_hashes` (during `inspect`) after labeling containers with `docker inspect --format '{{json .Config.Labels}}'`: the number of output lines did not match the number of inspected containers. The library assumes a 1:1 row-per-container result, so a mismatch indicates the engine returned unexpected output and it aborts rather than mapping hashes incorrectly.","triggerScenarios":"The container engine (docker/podman) returns fewer or more lines than the IDs passed to inspect — e.g. a container exits/is removed between listing and inspection, the engine emits extra warnings on stdout, or a non-Compose frontend prints additional lines.","commonSituations":"Racy container lifecycle during a concurrent `compose down`/restart; using a compose wrapper whose output is polluted; engine versions that print notices on stdout instead of stderr.","solutions":["Re-run the mise command; if a container was being torn down concurrently, the race resolves itself","Ensure the configured compose command/engine is Docker Compose v2 with clean stdout behavior","Check engine health (`docker ps`) and retry after containers settle"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// preflight: ensure engine responds and containers are stable\ndocker ps --format '{{.ID}}'","typeGuard":null,"tryCatchPattern":"match inspect_result {\n    Err(e) if e.to_string().contains(\"unexpected number of rows\") => retry_with_backoff(2),\n    other => other,\n}","preventionTips":["Avoid concurrent compose down/up while mise inspects the project","Use standard Docker Compose v2 frontends with clean stdout","Retry transiently; the failure is usually a race"],"tags":["docker","race-condition","invariant"],"backgroundTag":"unexpected-response-shape","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}