t8y2/dbx · error
checked one native platform
Error message
checked one native platform
What it means
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.
Source
Thrown at crates/dbx-core/src/agent_service.rs:2594
})?;
}
am.stop_daemon_by_key(&info.db_type).await;
result.drivers_installed.push(info.db_type);
Ok(result)
}
fn tar_zstd_driver_package_info(package_path: &Path) -> Result<TarZstdDriverPackageInfo, String> {
let registry = read_registry_from_tar_zstd(package_path)?;
if registry.drivers.len() != 1 {
return Err("A tar.zst driver package must contain exactly one driver".to_string());
}
let (db_type, driver) = registry.drivers.iter().next().expect("checked one driver");
validate_offline_driver_key(db_type)?;
let current_platform = AgentManager::current_platform();
let (native_platform, native_artifact) = if let Some(artifact) = driver.native.get(current_platform) {
(Some(current_platform.to_string()), Some(artifact))
} else if driver.native.len() == 1 {
let (platform, artifact) = driver.native.iter().next().expect("checked one native platform");
(Some(platform.clone()), Some(artifact))
} else {
(None, None)
};
let jar_artifact = usable_driver_jar(driver);
let (kind, artifact) = match (native_artifact, jar_artifact) {
(Some(_), Some(_)) => {
return Err("A tar.zst driver package must contain exactly one driver artifact".to_string());
}
(Some(artifact), None) => (DriverArtifactKind::Native, artifact),
(None, Some(artifact)) => (DriverArtifactKind::Jar, artifact),
(None, None) if !driver.native.is_empty() => {
return Err(format!("Driver package does not support platform: {current_platform}"));
}
(None, None) => return Err("A tar.zst driver package contains no driver artifact".to_string()),
};
if artifact.format.is_some() {
return Err("Nested driver packages are not supported".to_string());View on GitHub (pinned to c0390bff16)
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.
Example fix
// before
let (platform, artifact) = driver.native.iter().next().expect("checked one native platform");
// after
let Some((platform, artifact)) = driver.native.iter().next() else {
return Err("driver package has no native artifacts".to_string());
}; Defensive patterns
Strategy: type-guard
Validate before calling
// check native artifact layout before resolving platform artifacts
let driver = ®istry.drivers.values().next().unwrap();
if driver.native.len() > 1 && !driver.native.contains_key(AgentManager::current_platform()) {
return Err("ambiguous native artifacts: multiple platforms and none matches host".into());
} Type guard
fn single_native<'a>(driver: &'a OfflineDriver) -> Option<(&'a str, &'a DriverArtifact)> {
if driver.native.len() == 1 { driver.native.iter().next() } else { None }
} Try / catch
let Some((platform, artifact)) = driver.native.iter().next() else {
return Err("driver has no native artifacts".to_string());
}; Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- checked one driver
- a batch cancellation token is always available
- driver token registered
- a cancellation token is always available
- root count checked above
AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05).
Data as JSON: /api/errors/21d8ea9ef312c529.
Report an issue: GitHub.