{"record":{"id":"a2704bfa1c344483","repo":"t8y2/dbx","slug":"checked-one-driver","errorCode":null,"errorMessage":"checked one driver","messagePattern":"checked one driver","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/dbx-core/src/agent_service.rs","lineNumber":2588,"sourceCode":"                InstalledDriver {\n                    version: info.version.clone(),\n                    installed_at: chrono::Utc::now().to_rfc3339(),\n                    jre: info.jre.clone(),\n                },\n            );\n        })?;\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() => {","sourceCodeStart":2570,"sourceCodeEnd":2606,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/crates/dbx-core/src/agent_service.rs#L2570-L2606","documentation":"tar_zstd_driver_package_info first validates that a tar.zst offline driver package contains exactly one driver, then calls registry.drivers.iter().next().expect(\"checked one driver\") to extract it. The expect relies on the length check immediately above; it can only panic if the validation and extraction are separated or the length check is bypassed, which would be a code-invariant break.","triggerScenarios":"Programmatically impossible when the preceding `if registry.drivers.len() != 1 { return Err(...) }` guard is intact; it panics only if the guard is removed/reordered during refactoring or iter().next() is called on a mutated map. The real user-facing failure from this area is the Err \"A tar.zst driver package must contain exactly one driver\".","commonSituations":"Users building offline driver packages with zero or multiple drivers hit the Err message; developers refactoring the parsing function may turn the silent guard into a panic; packages built by older tooling versions with different layouts.","solutions":["Keep the len()!=1 guard immediately before extraction; never call iter().next() without it.","If you need a multi-driver tar.zst, use the registry-import path that supports multiple drivers instead of this single-driver helper.","For robustness, use a match on registry.drivers.len() returning a Result rather than expect.","Rebuild/repackage the offline driver so the archive contains exactly one driver."],"exampleFix":"// before\nlet (db_type, driver) = registry.drivers.iter().next().expect(\"checked one driver\");\n// after\nlet Some((db_type, driver)) = registry.drivers.into_iter().next() else {\n    return Err(\"A tar.zst driver package must contain exactly one driver\".to_string());\n};","handlingStrategy":"validation","validationCode":"// before importing a tar.zst driver package, check the registry layout\nlet registry = read_registry_from_tar_zstd(path)?;\nif registry.drivers.len() != 1 {\n    return Err(format!(\n        \"package must contain exactly one driver, found {}\",\n        registry.drivers.len()\n    ));\n}","typeGuard":"fn single_driver(registry: &DriverRegistry) -> Option<(&str, &OfflineDriver)> {\n    if registry.drivers.len() == 1 { registry.drivers.iter().next() } else { None }\n}","tryCatchPattern":"let Some((db_type, driver)) = registry.drivers.iter().next() else {\n    return Err(\"A tar.zst driver package must contain exactly one driver\".to_string());\n};","preventionTips":["Build offline driver packages with exactly one driver entry.","Validate package layout right after packaging in CI.","Keep length guards adjacent to iterator extraction.","Use a single_entry helper returning Result instead of expect."],"tags":["rust","panic","invariant","driver-package","offline-import"],"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"}