{"record":{"id":"e33ac3b3e11af2a4","repo":"vectordotdev/vector","slug":"key-is-not-found","errorCode":null,"errorMessage":"Key is not found: {:?}","messagePattern":"Key is not found: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/vector-core/src/event/log_event.rs","lineNumber":728,"sourceCode":"    type Error = crate::Error;\n\n    fn try_into(self) -> Result<serde_json::Value, Self::Error> {\n        Ok(serde_json::to_value(&self.inner.fields)?)\n    }\n}\n\n#[cfg(any(test, feature = \"test\"))]\nimpl<T> std::ops::Index<T> for LogEvent\nwhere\n    T: AsRef<str>,\n{\n    type Output = Value;\n\n    fn index(&self, key: T) -> &Value {\n        self.parse_path_and_get_value(key.as_ref())\n            .ok()\n            .flatten()\n            .unwrap_or_else(|| panic!(\"Key is not found: {:?}\", key.as_ref()))\n    }\n}\n\nimpl<K, V> Extend<(K, V)> for LogEvent\nwhere\n    K: AsRef<str>,\n    V: Into<Value>,\n{\n    fn extend<I: IntoIterator<Item = (K, V)>>(&mut self, iter: I) {\n        for (k, v) in iter {\n            if let Ok(path) = parse_target_path(k.as_ref()) {\n                self.insert(&path, v.into());\n            }\n        }\n    }\n}\n\n// Allow converting any kind of appropriate key/value iterator directly into a LogEvent.","sourceCodeStart":710,"sourceCodeEnd":746,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/lib/vector-core/src/event/log_event.rs#L710-L746","documentation":"This panic comes from the `Index` implementation of `LogEvent`: indexing a log event with `log[key]` guarantees a `&Value` return, so when the path lookup (`parse_path_and_get_value`) yields nothing the implementation panics with the missing key. The library throws it because the indexing operator cannot express a fallible lookup. It means the requested path does not exist in the event (or the path is malformed/points through a non-object value).","triggerScenarios":"Calling `log[\"field\"][\"sub\"]` (or `Index::index`) where `field` or `field.sub` is absent, or where an intermediate segment resolves to a non-object/non-array value so the path cannot be traversed; also via VRL/lookup helpers that use the Index impl for guaranteed access.","commonSituations":"Referencing a field that a source/transform did not always populate (e.g. optional HTTP header), typos or case mismatches in key names, parsing events where nested objects may be missing, and downstream code assuming a field added by an earlier transform is always present.","solutions":["Use the fallible lookup `log.get(\"key\")` (or `parse_path_and_get_value`) and handle the None case instead of indexing","Guard with a conditional: only index when the path was confirmed to exist","Ensure upstream transforms/sources actually insert the field before it is indexed","Verify key spelling and path segment types against the actual event schema"],"exampleFix":"// before\nlet level = log[\"level\"].as_str().unwrap_or(\"info\");\n// after\nlet level = log.get(\"level\").and_then(|v| v.as_str()).unwrap_or(\"info\");","handlingStrategy":"validation","validationCode":"let v = event.get(\"key\"); if v.is_none() { return Err(missing_key_error(\"key\")); }","typeGuard":"fn has_key(e: &LogEvent, path: &str) -> bool { e.get(path).is_some() }","tryCatchPattern":null,"preventionTips":["Use fallible get() over indexing"],"tags":["rust","panic","key-lookup","log-event"],"backgroundTag":"record-not-found","analyzedSha":"bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013","analyzedAt":"2026-09-16T02:53:35.741Z","contentChangedAt":"2026-09-16T02:53:35.741Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}