{"record":{"id":"21d8ea9ef312c529","repo":"t8y2/dbx","slug":"checked-one-native-platform","errorCode":null,"errorMessage":"checked one native platform","messagePattern":"checked one native platform","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/dbx-core/src/agent_service.rs","lineNumber":2594,"sourceCode":"        })?;\n    }\n    am.stop_daemon_by_key(&info.db_type).await;\n    result.drivers_installed.push(info.db_type);\n    Ok(result)\n}\n\nfn tar_zstd_driver_package_info(package_path: &Path) -> Result<TarZstdDriverPackageInfo, String> {\n    let registry = read_registry_from_tar_zstd(package_path)?;\n    if registry.drivers.len() != 1 {\n        return Err(\"A tar.zst driver package must contain exactly one driver\".to_string());\n    }\n    let (db_type, driver) = registry.drivers.iter().next().expect(\"checked one driver\");\n    validate_offline_driver_key(db_type)?;\n    let current_platform = AgentManager::current_platform();\n    let (native_platform, native_artifact) = if let Some(artifact) = driver.native.get(current_platform) {\n        (Some(current_platform.to_string()), Some(artifact))\n    } else if driver.native.len() == 1 {\n        let (platform, artifact) = driver.native.iter().next().expect(\"checked one native platform\");\n        (Some(platform.clone()), Some(artifact))\n    } else {\n        (None, None)\n    };\n    let jar_artifact = usable_driver_jar(driver);\n    let (kind, artifact) = match (native_artifact, jar_artifact) {\n        (Some(_), Some(_)) => {\n            return Err(\"A tar.zst driver package must contain exactly one driver artifact\".to_string());\n        }\n        (Some(artifact), None) => (DriverArtifactKind::Native, artifact),\n        (None, Some(artifact)) => (DriverArtifactKind::Jar, artifact),\n        (None, None) if !driver.native.is_empty() => {\n            return Err(format!(\"Driver package does not support platform: {current_platform}\"));\n        }\n        (None, None) => return Err(\"A tar.zst driver package contains no driver artifact\".to_string()),\n    };\n    if artifact.format.is_some() {\n        return Err(\"Nested driver packages are not supported\".to_string());","sourceCodeStart":2576,"sourceCodeEnd":2612,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/crates/dbx-core/src/agent_service.rs#L2576-L2612","documentation":"In the same tar_zstd_driver_package_info function, after confirming the package has exactly one driver, the code handles the platform branch: if the single driver has exactly one native artifact and the current platform is not among them, it takes driver.native.iter().next().expect(\"checked one native platform\"). Like 1086, the expect is protected by the driver.native.len() == 1 check; it panics only if that guard is missing or the map was mutated.","triggerScenarios":"Only reachable if the `else if driver.native.len() == 1` guard is bypassed (refactor/mutation). Real-world trigger for users is a driver package whose single driver has zero or multiple native artifacts for non-current platforms, which falls through to the (None, None) branch rather than panicking.","commonSituations":"Offline driver packages built for a different platform than the host; packages containing native binaries for several OS/arch combinations; packages missing native artifacts entirely (JAR-only drivers) — all take the None branch, not the panic.","solutions":["Preserve the driver.native.len() == 1 guard directly above the iter().next() extraction.","Prefer a helper like single_entry(map) returning Result to avoid dual guards + expects.","When packaging drivers, ship exactly one native artifact per driver or rely on the current-platform key to avoid ambiguous fallback.","If multiple native platforms are intentional, extend the function to select by arch compatibility instead of len()==1."],"exampleFix":"// before\nlet (platform, artifact) = driver.native.iter().next().expect(\"checked one native platform\");\n// after\nlet Some((platform, artifact)) = driver.native.iter().next() else {\n    return Err(\"driver package has no native artifacts\".to_string());\n};","handlingStrategy":"type-guard","validationCode":"// check native artifact layout before resolving platform artifacts\nlet driver = &registry.drivers.values().next().unwrap();\nif driver.native.len() > 1 && !driver.native.contains_key(AgentManager::current_platform()) {\n    return Err(\"ambiguous native artifacts: multiple platforms and none matches host\".into());\n}","typeGuard":"fn single_native<'a>(driver: &'a OfflineDriver) -> Option<(&'a str, &'a DriverArtifact)> {\n    if driver.native.len() == 1 { driver.native.iter().next() } else { None }\n}","tryCatchPattern":"let Some((platform, artifact)) = driver.native.iter().next() else {\n    return Err(\"driver has no native artifacts\".to_string());\n};","preventionTips":["Ship either a current-platform native artifact or exactly one native artifact per driver.","Test package parsing on a host whose platform differs from the package's target.","Keep the len()==1 guard next to the iter().next() call.","Prefer explicit platform-arch selection logic over single-entry assumptions when multi-platform packages are expected."],"tags":["rust","panic","invariant","platform","driver-package"],"backgroundTag":"empty-collection-unwrapping","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}