sxyazi/yazi · error

Cannot get the value for the key `{key}`

Error message

Cannot get the value for the key `{key}`

What it means

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.

Source

Thrown at yazi-ffi/src/cf_dict.rs:25

use super::cf_string::CFString;

pub struct CFDict(CFDictionaryRef);

impl CFDict {
	pub fn take(dict: CFDictionaryRef) -> Result<Self> {
		if dict.is_null() {
			bail!("Cannot take a null pointer");
		}
		Ok(Self(dict))
	}

	fn value(&self, key: &str) -> Result<*const c_void> {
		let key_ = CFString::new(key)?;
		let mut value = std::ptr::null();
		if unsafe { CFDictionaryGetValueIfPresent(self.0, key_.as_void_ptr(), &mut value) } == 0
			|| value.is_null()
		{
			bail!("Cannot get the value for the key `{key}`");
		}
		Ok(value)
	}

	pub fn bool(&self, key: &str) -> Result<bool> {
		let value = self.value(key)?;
		#[allow(unexpected_cfgs)]
		Ok(unsafe { msg_send![value as *const AnyObject, boolValue] })
	}

	pub fn integer(&self, key: &str) -> Result<i64> {
		let value = self.value(key)?;
		#[allow(unexpected_cfgs)]
		Ok(unsafe { msg_send![value as *const AnyObject, longLongValue] })
	}

	pub fn os_string(&self, key: &str) -> Result<OsString> {
		ManuallyDrop::new(CFString(self.value(key)? as CFStringRef)).os_string()

View on GitHub (pinned to 5f901b886b)

Solutions

  1. Verify the exact CFDictionary key string expected by the metadata source (e.g. kICLauncher / custom-icon keys) and fix typos or casing.
  2. Check key presence before extraction by adding a contains/get-if-present helper instead of assuming the key exists.
  3. Treat the error as 'attribute absent' and fall back to defaults rather than propagating it as a hard failure.

Example fix

// before
let icon = dict.bool("CustomIcon")?;
// after
let icon = dict.bool("CustomIcon").unwrap_or(false);
Defensive patterns

Strategy: fallback

Validate before calling

// Rust: check presence first via CFDictionaryGetValueIfPresent
let present = unsafe { CFDictionaryGetValueIfPresent(dict, key.as_void_ptr(), std::ptr::null_mut()) } != 0;
if !present { /* skip this key */ }

Type guard

fn has_key(dict: &CFDict, key: &str) -> bool { dict.value(key).is_ok() }

Try / catch

let v = dict.bool("CustomIcon").unwrap_or(false); // treat absent key as default

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of sxyazi/yazi@5f901b886b (2026-09-02). Data as JSON: /api/errors/5842f625ea0e0051. Report an issue: GitHub.