{"record":{"id":"31e912511d4ab8c8","repo":"vectordotdev/vector","slug":"unable-to-serialize-vrl-value","errorCode":null,"errorMessage":"Unable to serialize VRL value","messagePattern":"Unable to serialize VRL value","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/vector-config/src/external/vrl.rs","lineNumber":66,"sourceCode":"\n    fn generate_schema(_: &RefCell<SchemaGenerator>) -> Result<SchemaObject, GenerateError> {\n        // We don't have any constraints on the inputs\n        Ok(SchemaObject::default())\n    }\n}\n\nimpl ToValue for VrlValue {\n    /// Converts a `VrlValue` into a `serde_json::Value`.\n    ///\n    /// This conversion should always succeed, though it may result in a loss\n    /// of type information for some value types.\n    ///\n    /// # Panics\n    ///\n    /// This function will panic if serialization fails, which is not expected\n    /// under normal circumstances.\n    fn to_value(&self) -> Value {\n        serde_json::to_value(self).expect(\"Unable to serialize VRL value\")\n    }\n}\n","sourceCodeStart":48,"sourceCodeEnd":69,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/lib/vector-config/src/external/vrl.rs#L48-L69","documentation":"In vector-config's VRL integration, `ToValue for vrl::Value` serializes a VRL runtime value to JSON and explicitly panics with \"Unable to serialize VRL value\" on failure. The doc comment notes this is not expected under normal circumstances because VRL values are designed to be JSON-representable. Because `to_value` has no error channel, any serialization failure surfaces as a panic during schema/config generation.","triggerScenarios":"Calling `vrl::Value::to_value()` while generating schemas or metadata when the VRL value's serde representation is rejected by serde_json — e.g. a value containing non-string map keys (regexes/bytes variants) or an NaN/infinite float that serde_json cannot encode.","commonSituations":"Schema generation for transforms whose config embeds VRL values; constructing VRL values programmatically (with regex or bytes objects) and passing them through config metadata serialization.","solutions":["Check whether the VRL value contains non-JSON-representable variants (non-string map keys, NaN/Inf floats) before calling to_value","Normalize the value first (convert regexes to their string form, replace non-finite floats)","If calling from your own code, use serde_json::to_value directly and handle the Result instead of relying on ToValue"],"exampleFix":"// before\nlet v: serde_json::Value = value.to_value();\n// after\nlet v = serde_json::to_value(&value)\n    .unwrap_or_else(|e| panic!(\"Unable to serialize VRL value: {e}\")); // keeps cause; or handle Err","handlingStrategy":"validation","validationCode":"// Guard against non-JSON-representable VRL values first:\nif !serde_json::to_value(&vrl_value).is_ok() {\n    eprintln!(\"VRL value contains non-JSON-representable data\");\n}","typeGuard":"fn is_json_safe(vrl_value: &vrl::Value) -> bool {\n    serde_json::to_value(vrl_value).is_ok()\n}","tryCatchPattern":"// to_value panics by design; isolate if calling externally:\nlet result = std::panic::catch_unwind(|| vrl_value.to_value());","preventionTips":["Avoid constructing VRL values with regex/bytes objects for config metadata","Replace NaN/Inf floats before serialization","Use serde_json::to_value directly to get an Err instead of a panic"],"tags":["rust","vrl","json","serialization","panic"],"backgroundTag":"json-serialization-failed","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"}