{"record":{"id":"cd20f317783c2c75","repo":"napi-rs/napi-rs","slug":"invalid-key-filter","errorCode":null,"errorMessage":"Invalid key filter [{}]","messagePattern":"Invalid key filter \\[(.+?)\\]","errorType":"validation","errorClass":"InvalidArg","httpStatus":null,"severity":"error","filePath":"crates/napi/src/bindgen_runtime/js_values/object.rs","lineNumber":1054,"sourceCode":"  Enumerable,\n  Configurable,\n  SkipStrings,\n  SkipSymbols,\n}\n\n#[cfg(feature = \"napi6\")]\nimpl TryFrom<sys::napi_key_filter> for KeyFilter {\n  type Error = Error;\n\n  fn try_from(value: sys::napi_key_filter) -> Result<Self> {\n    match value {\n      sys::KeyFilter::all_properties => Ok(Self::AllProperties),\n      sys::KeyFilter::writable => Ok(Self::Writable),\n      sys::KeyFilter::enumerable => Ok(Self::Enumerable),\n      sys::KeyFilter::configurable => Ok(Self::Configurable),\n      sys::KeyFilter::skip_strings => Ok(Self::SkipStrings),\n      sys::KeyFilter::skip_symbols => Ok(Self::SkipSymbols),\n      _ => Err(Error::new(\n        crate::Status::InvalidArg,\n        format!(\"Invalid key filter [{value}]\"),\n      )),\n    }\n  }\n}\n\n#[cfg(feature = \"napi6\")]\nimpl From<KeyFilter> for sys::napi_key_filter {\n  fn from(value: KeyFilter) -> Self {\n    match value {\n      KeyFilter::AllProperties => sys::KeyFilter::all_properties,\n      KeyFilter::Writable => sys::KeyFilter::writable,\n      KeyFilter::Enumerable => sys::KeyFilter::enumerable,\n      KeyFilter::Configurable => sys::KeyFilter::configurable,\n      KeyFilter::SkipStrings => sys::KeyFilter::skip_strings,\n      KeyFilter::SkipSymbols => sys::KeyFilter::skip_symbols,\n    }","sourceCodeStart":1036,"sourceCodeEnd":1072,"githubUrl":"https://github.com/napi-rs/napi-rs/blob/39bd1205e480a453a2da2601a760bde5a71ed016/crates/napi/src/bindgen_runtime/js_values/object.rs#L1036-L1072","documentation":"This error is raised converting a raw `sys::KeyFilter` bitmask/enum value into the safe `KeyFilter` Rust enum during object key enumeration. Only the known variants (all_properties, writable, enumerable, configurable, skip_strings, skip_symbols) are accepted; any other value yields `Status::InvalidArg`.","triggerScenarios":"Enumerating object properties with key filter options where the raw `napi_key_filter` value does not match any known variant — from corrupted/foreign enum values, version drift between napi-sys and Node headers, or unsafe transmutes of raw integers.","commonSituations":"Hand-building raw key filters in unsafe FFI code; building against mismatched Node header versions that redefine filter bit values; copy-pasted raw values from a different N-API version.","solutions":["Use the safe `KeyFilter` Rust enum variants instead of raw sys values","Rebuild with napi-sys matching your target Node version","Verify no unsafe transmute of arbitrary integers into sys::KeyFilter exists in your code"],"exampleFix":"// before\nlet filter: sys::KeyFilter = unsafe { std::mem::transmute(0xFFu32) };\n// after\nlet filter = KeyFilter::AllProperties;","handlingStrategy":"type-guard","validationCode":"let filter = KeyFilter::AllProperties; // safe variant only","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Construct key filters from the safe Rust enum","Avoid copying raw bit values from other N-API versions","Rebuild bindings when upgrading Node versions"],"tags":["napi","enum","invalid-argument","key-filter"],"backgroundTag":"invalid-enum-value","analyzedSha":"39bd1205e480a453a2da2601a760bde5a71ed016","analyzedAt":"2026-09-13T20:31:47.814Z","contentChangedAt":"2026-09-13T20:31:47.814Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}