{"record":{"id":"934f676fe545d2dc","repo":"ClementTsang/bottom","slug":"missing-key","errorCode":null,"errorMessage":"missing key","messagePattern":"missing key","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/collection/disks/unix/macos/io_kit/io_object.rs","lineNumber":111,"sourceCode":") -> anyhow::Result<CFDictionary<CFString, CFType>> {\n    let key = CFString::from_static_string(raw_key);\n\n    dict.find(&key)\n        .map(|value_ref| {\n            // SAFETY: Only used for debug asserts, system API call that should\n            // be safe.\n            unsafe {\n                debug_assert!(value_ref.type_of() == CFDictionaryGetTypeID());\n            }\n\n            // \"Casting\" `CFDictionary<*const void, *const void>` into a needed\n            // dict type\n            let ptr = value_ref.to_void() as CFDictionaryRef;\n\n            // SAFETY: System API call, it should be safe?\n            unsafe { CFDictionary::wrap_under_get_rule(ptr) }\n        })\n        .ok_or_else(|| anyhow!(\"missing key\"))\n}\n\npub fn get_i64(\n    dict: &CFDictionary<CFString, CFType>, raw_key: &'static str,\n) -> anyhow::Result<i64> {\n    let key = CFString::from_static_string(raw_key);\n\n    dict.find(&key)\n        .and_then(|value_ref| {\n            // SAFETY: Only used for debug asserts, system API call that should\n            // be safe.\n            unsafe {\n                debug_assert!(value_ref.type_of() == CFNumberGetTypeID());\n            }\n            value_ref.downcast::<CFNumber>()\n        })\n        .and_then(|number| number.to_i64())\n        .ok_or_else(|| anyhow!(\"missing key\"))","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/ClementTsang/bottom/blob/b77d3175028849824e987c35177e8f61450d72e7/src/collection/disks/unix/macos/io_kit/io_object.rs#L93-L129","documentation":"macOS I/O Kit helper `get_dict(dict, raw_key)` looks up `raw_key` in a `CFDictionary` of an IOService/IORegistryEntry and bails with 'missing key' when the key is absent or the value cannot be wrapped as a CFDictionary. Called from `get_device_io`, it means the expected IORegistry dictionary entry (e.g. statistics/protocol characteristics) does not exist for this device.","triggerScenarios":"`get_device_io` querying a disk whose IORegistry entry lacks the expected dictionary key; the value under the key exists but is not a CFDictionary; device hardware/firmware does not publish the expected IORegistry data; virtual or external drives missing the key.","commonSituations":"Running on Macs with virtualized disks (AVFarming, VMs) or USB bridges that do not expose IORegistry statistics; macOS version differences in IORegistry layout; requesting keys from non-physical devices.","solutions":["Treat missing keys as optional data — skip the device or default the value rather than failing the whole collection","Verify the key string matches the exact IORegistry key name (case-sensitive) for your macOS version","Check the device in IORegistryExplorer to confirm which keys it actually publishes","Filter device classes (only physical/internal disks) before querying IOStatistics"],"exampleFix":"// before\nlet dict = io_object::get_dict(&dict, \"kIOPropertyNVMeSMARTData\")?;\n// after\nlet smart = match io_object::get_dict(&dict, \"kIOPropertyNVMeSMARTData\") {\n    Ok(d) => d,\n    Err(_) => {\n        // device does not expose this key; continue with defaults\n        Default::default()\n    },\n};","handlingStrategy":"fallback","validationCode":"// Confirm the key exists before requesting a dictionary value\nlet key = core_foundation::string::CFString::new(\"target_key\");\nif dict.find(key).is_some() {\n    let d = io_object::get_dict(&dict, \"target_key\")?;\n} else {\n    // device does not publish this key; use defaults\n}","typeGuard":"fn optional_dict(dict: &CFDictionary<CFString, CFType>, key: &str)\n    -> Option<CFDictionary<CFString, CFType>> {\n    io_object::get_dict(dict, key).ok()\n}","tryCatchPattern":"let io_dict = match io_object::get_dict(&entry_dict, \"IOStatistics\") {\n    Ok(d) => Some(d),\n    Err(e) if e.to_string() == \"missing key\" => None,\n    Err(e) => return Err(e),\n};","preventionTips":["Inspect the device in IORegistryExplorer to confirm which keys it publishes","Treat IOKit keys as optional — virtual/USB disks often lack them","Pin key names per macOS version; they can change between releases","Filter to device classes known to expose the statistics you need"],"tags":["macos","iokit","cfdictionary","disks","missing-key"],"backgroundTag":"resource-not-found","analyzedSha":"b77d3175028849824e987c35177e8f61450d72e7","analyzedAt":"2026-09-07T14:53:21.246Z","contentChangedAt":"2026-09-07T14:53:21.246Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}