{"record":{"id":"601a421d3d716c19","repo":"ClementTsang/bottom","slug":"ioregistryentrycreatecfproperties-failed-error-co","errorCode":null,"errorMessage":"IORegistryEntryCreateCFProperties failed, error code {result}.","messagePattern":"IORegistryEntryCreateCFProperties failed, error code (.+?)\\.","errorType":"error_code","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/collection/disks/unix/macos/io_kit/io_object.rs","lineNumber":41,"sourceCode":"\nimpl IoObject {\n    /// Returns a typed dictionary with this object's properties.\n    pub fn properties(&self) -> anyhow::Result<CFDictionary<CFString, CFType>> {\n        // SAFETY: The IOKit call should be fine, the arguments are safe. The\n        // `assume_init` should also be fine, as we guard against it with a\n        // check against `result` to ensure it succeeded.\n        unsafe {\n            let mut props = mem::MaybeUninit::<CFMutableDictionaryRef>::uninit();\n\n            let result = IORegistryEntryCreateCFProperties(\n                self.0,\n                props.as_mut_ptr(),\n                kCFAllocatorDefault,\n                0,\n            );\n\n            if result != kern_return::KERN_SUCCESS {\n                bail!(\"IORegistryEntryCreateCFProperties failed, error code {result}.\")\n            } else {\n                let props = props.assume_init();\n                Ok(CFMutableDictionary::wrap_under_create_rule(props).to_immutable())\n            }\n        }\n    }\n\n    /// Gets the [`kIOServicePlane`] parent [`io_object_t`] for this\n    /// [`io_object_t`], if there is one.\n    pub fn service_parent(&self) -> anyhow::Result<IoObject> {\n        let mut parent: io_registry_entry_t = 0;\n\n        // SAFETY: IOKit call, the arguments should be safe.\n        let result = unsafe {\n            IORegistryEntryGetParentEntry(self.0, kIOServicePlane.as_ptr().cast(), &mut parent)\n        };\n\n        if result != kern_return::KERN_SUCCESS {","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/ClementTsang/bottom/blob/b77d3175028849824e987c35177e8f61450d72e7/src/collection/disks/unix/macos/io_kit/io_object.rs#L23-L59","documentation":"The properties helper calls IORegistryEntryCreateCFProperties to read all registry properties of an IOKit entry into a CFMutableDictionary. If the kernel call returns a non-KERN_SUCCESS result, this error reports the kern_return_t code.","triggerScenarios":"Calling properties() (used while walking the IOKit disk/IO hierarchy in io_stats) on an io_object whose registry entry is invalid, already destroyed, or lacks a connection to the registry.","commonSituations":"Enumerating disks while devices are hot-unplugged mid-iteration, or querying entries obtained from a failed/partial IOKit traversal.","solutions":["Re-enumerate the IOKit entries rather than reusing stale io_object handles","Check the returned error code (e.g. kIOReturnBadArgument implies an invalid entry)","Retry disk stats collection; transient failures often resolve on the next sweep","Guard device-removal races by tolerating per-device failures during iteration"],"exampleFix":"// before\nlet props = entry.properties()?;\n// after\nlet props = match entry.properties() {\n    Ok(p) => p,\n    Err(e) => { log::debug!(\"device vanished, skipping: {e}\"); continue; },\n};","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match entry.properties() {\n    Ok(p) => process(p),\n    Err(e) if e.to_string().contains(\"IORegistryEntryCreateCFProperties\") => {\n        log::debug!(\"device entry vanished: {e}\"); // skip device\n    },\n    Err(e) => return Err(e),\n}","preventionTips":["Re-enumerate IOKit entries each sweep instead of caching io_objects","Expect hot-unplug races and skip failing devices","Log the kern_return_t code for diagnosis","Retry on the next collection interval"],"tags":["macos","iokit","disks","system-api"],"backgroundTag":"api-error-response","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"}