{"record":{"id":"55bbfae57aef315d","repo":"vectordotdev/vector","slug":"failed-type-coercion-self-is-not-a-log-refere","errorCode":null,"errorMessage":"Failed type coercion, {self:?} is not a log reference","messagePattern":"Failed type coercion, (.+?) is not a log reference","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/vector-core/src/event/ref.rs","lineNumber":28,"sourceCode":"pub enum EventRef<'a> {\n    /// Reference to a `LogEvent`\n    Log(&'a LogEvent),\n    /// Reference to a `Metric`\n    Metric(&'a Metric),\n    /// Reference to a `TraceEvent`\n    Trace(&'a TraceEvent),\n}\n\nimpl<'a> EventRef<'a> {\n    /// Extract the `LogEvent` reference in this.\n    ///\n    /// # Panics\n    ///\n    /// This will panic if this is not a `LogEvent` reference.\n    pub fn as_log(self) -> &'a LogEvent {\n        match self {\n            Self::Log(log) => log,\n            _ => panic!(\"Failed type coercion, {self:?} is not a log reference\"),\n        }\n    }\n\n    /// Convert this reference into a new `LogEvent` by cloning.\n    ///\n    /// # Panics\n    ///\n    /// This will panic if this is not a `LogEvent` reference.\n    pub fn into_log(self) -> LogEvent {\n        match self {\n            Self::Log(log) => log.clone(),\n            _ => panic!(\"Failed type coercion, {self:?} is not a log reference\"),\n        }\n    }\n\n    /// Extract the `Metric` reference in this.\n    ///\n    /// # Panics","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/vectordotdev/vector/blob/3708c39b12a93212ed8b8d7510b4cc7769cb5864/lib/vector-core/src/event/ref.rs#L10-L46","documentation":"`EventRef<'a>` is a borrowed, clone-free view over an `Event` (Log/Metric/Trace reference variants) used to avoid allocations on hot paths. `EventRef::as_log` (lib/vector-core/src/event/ref.rs:26-32) unwraps only the `Log` variant and panics with a debug dump otherwise, per its `# Panics` doc. `into_log` on the same type additionally clones the borrowed log event.","triggerScenarios":"Calling `event_ref.as_log()` (or `event_ref.into_log()`) on an `EventRef::Metric`/`EventRef::Trace` — e.g. fan-out code that iterates pipeline outputs as `EventRef`s and forwards each to a log-only consumer such as a log sink acknowledgement or serializer path.","commonSituations":"Custom sinks or middleware consuming `Vec<EventRef>` from a topology output where metrics/traces share the stream; refactoring owned-`Event` code (which used `try_into_log`) to the zero-copy `EventRef` API and dropping the variant check in the process.","solutions":["Match on the `EventRef` variant and only call `as_log` in the `Self::Log` arm.","Skip or emit an internal error event for non-log variants instead of coercing.","Keep log-only consumers on a routed branch that only ever emits log events."],"exampleFix":"// before\nlet log = event_ref.as_log(); // panics for Metric/Trace refs\n\n// after\nmatch event_ref {\n    EventRef::Log(log) => forward(log),\n    EventRef::Metric(_) | EventRef::Trace(_) => emit!(WrongSignalType),\n}","handlingStrategy":"type-guard","validationCode":"if let EventRef::Log(_) = event_ref {\n    let log = event_ref.as_log();\n}","typeGuard":"fn is_log_ref(r: &EventRef<'_>) -> bool { matches!(r, EventRef::Log(_)) }","tryCatchPattern":null,"preventionTips":["Match on the EventRef variant in fan-out code instead of calling as_log() directly.","When porting owned-Event code to EventRef, carry over the variant checks that used try_into_log.","Skip non-log refs with an emitted diagnostic so mixed pipelines degrade gracefully."],"tags":["rust","vector","event","type-coercion","zero-copy","panic"],"backgroundTag":"event-type-coercion-failure","analyzedSha":"3708c39b12a93212ed8b8d7510b4cc7769cb5864","analyzedAt":"2026-08-20T07:02:18.786Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}