{"record":{"id":"5842f625ea0e0051","repo":"sxyazi/yazi","slug":"cannot-get-the-value-for-the-key-key","errorCode":null,"errorMessage":"Cannot get the value for the key `{key}`","messagePattern":"Cannot get the value for the key `(.+?)`","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"yazi-ffi/src/cf_dict.rs","lineNumber":25,"sourceCode":"use super::cf_string::CFString;\n\npub struct CFDict(CFDictionaryRef);\n\nimpl CFDict {\n\tpub fn take(dict: CFDictionaryRef) -> Result<Self> {\n\t\tif dict.is_null() {\n\t\t\tbail!(\"Cannot take a null pointer\");\n\t\t}\n\t\tOk(Self(dict))\n\t}\n\n\tfn value(&self, key: &str) -> Result<*const c_void> {\n\t\tlet key_ = CFString::new(key)?;\n\t\tlet mut value = std::ptr::null();\n\t\tif unsafe { CFDictionaryGetValueIfPresent(self.0, key_.as_void_ptr(), &mut value) } == 0\n\t\t\t|| value.is_null()\n\t\t{\n\t\t\tbail!(\"Cannot get the value for the key `{key}`\");\n\t\t}\n\t\tOk(value)\n\t}\n\n\tpub fn bool(&self, key: &str) -> Result<bool> {\n\t\tlet value = self.value(key)?;\n\t\t#[allow(unexpected_cfgs)]\n\t\tOk(unsafe { msg_send![value as *const AnyObject, boolValue] })\n\t}\n\n\tpub fn integer(&self, key: &str) -> Result<i64> {\n\t\tlet value = self.value(key)?;\n\t\t#[allow(unexpected_cfgs)]\n\t\tOk(unsafe { msg_send![value as *const AnyObject, longLongValue] })\n\t}\n\n\tpub fn os_string(&self, key: &str) -> Result<OsString> {\n\t\tManuallyDrop::new(CFString(self.value(key)? as CFStringRef)).os_string()","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/sxyazi/yazi/blob/5f901b886b14de1f17460b6e52e9de5d67f8aba9/yazi-ffi/src/cf_dict.rs#L7-L43","documentation":"CFDict::value looks up a key in a macOS Core Foundation CFDictionary and bails when the key is absent or the stored value pointer is NULL. This means the caller asked for a key that does not exist in the dictionary, not that the lookup API itself failed. Callers like bool/integer/os_string/path_buf surface it as an anyhow error to the Rust side.","triggerScenarios":"Calling d.bool(\"some key\"), d.integer(..), d.os_string(..), or d.path_buf(..) on a CFDictionary that has no entry for that key, or whose entry value is NULL. Typical source: reading Launch Services / Finder metadata (e.g. custom icon resource info) where an expected attribute key is missing for the queried file.","commonSituations":"Querying macOS-specific file metadata (resource forks, custom-icon flags) on files that simply lack the attribute; running on a macOS version that stores the info under a different key; passing a key string with wrong casing or typos.","solutions":["Verify the exact CFDictionary key string expected by the metadata source (e.g. kICLauncher / custom-icon keys) and fix typos or casing.","Check key presence before extraction by adding a contains/get-if-present helper instead of assuming the key exists.","Treat the error as 'attribute absent' and fall back to defaults rather than propagating it as a hard failure."],"exampleFix":"// before\nlet icon = dict.bool(\"CustomIcon\")?;\n// after\nlet icon = dict.bool(\"CustomIcon\").unwrap_or(false);","handlingStrategy":"fallback","validationCode":"// Rust: check presence first via CFDictionaryGetValueIfPresent\nlet present = unsafe { CFDictionaryGetValueIfPresent(dict, key.as_void_ptr(), std::ptr::null_mut()) } != 0;\nif !present { /* skip this key */ }","typeGuard":"fn has_key(dict: &CFDict, key: &str) -> bool { dict.value(key).is_ok() }","tryCatchPattern":"let v = dict.bool(\"CustomIcon\").unwrap_or(false); // treat absent key as default","preventionTips":["Confirm exact CF key strings against Apple headers/docs before use","Treat metadata lookups as optional attributes with defaults","Test on real macOS metadata sources, including files without the attribute"],"tags":["macos","core-foundation","missing-key","ffi"],"backgroundTag":"dictionary-key-not-found","analyzedSha":"5f901b886b14de1f17460b6e52e9de5d67f8aba9","analyzedAt":"2026-09-02T18:38:25.566Z","contentChangedAt":"2026-09-02T18:38:25.566Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}