{"record":{"id":"f9ddba7714b858a1","repo":"vectordotdev/vector","slug":"expected-utf-8","errorCode":null,"errorMessage":"Expected UTF-8.","messagePattern":"Expected UTF-8\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/transforms/lua/v1/mod.rs","lineNumber":233,"sourceCode":"                    }\n                })\n            })\n            .flatten(),\n        )\n    }\n}\n\nimpl mlua::UserData for LuaEvent {\n    fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {\n        methods.add_meta_method_mut(\n            mlua::MetaMethod::NewIndex,\n            |_lua, this, (key, value): (String, Option<mlua::Value>)| {\n                let key_path = parse_target_path(key.as_str()).map_err(|e| e.into_lua_err())?;\n                match value {\n                    Some(mlua::Value::String(string)) => {\n                        this.inner.as_mut_log().insert(\n                            &key_path,\n                            Value::from(string.to_str().expect(\"Expected UTF-8.\").to_owned()),\n                        );\n                    }\n                    Some(mlua::Value::Integer(integer)) => {\n                        this.inner\n                            .as_mut_log()\n                            .insert(&key_path, Value::Integer(integer));\n                    }\n                    Some(mlua::Value::Number(number)) if !number.is_nan() => {\n                        this.inner\n                            .as_mut_log()\n                            .insert(&key_path, Value::Float(NotNan::new(number).unwrap()));\n                    }\n                    Some(mlua::Value::Boolean(boolean)) => {\n                        this.inner\n                            .as_mut_log()\n                            .insert(&key_path, Value::Boolean(boolean));\n                    }\n                    Some(mlua::Value::Nil) | None => {","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/vectordotdev/vector/blob/3708c39b12a93212ed8b8d7510b4cc7769cb5864/src/transforms/lua/v1/mod.rs#L215-L251","documentation":"In the v1 Lua transform, assigning a string field with `event[\"field\"] = value` converts the Lua string through `to_str().expect(\"Expected UTF-8.\")`. Lua strings are raw byte arrays and mlua's `to_str()` errors on non-UTF-8 bytes, so assigning any binary string to an event field panics the transform and the pipeline task.","triggerScenarios":"A Lua script builds a non-UTF-8 byte string — `string.char(0xff)`, hex/protobuf-decoded blobs, `string.rep(\"\\xff\", 8)`, bytes passed through from a binary payload — and assigns it via the __newindex metamethod (`event[\"x\"] = value`).","commonSituations":"Lua transforms handling binary-ish data (compressed fragments, legacy single-byte encodings, length-prefixed wire formats); scripts ported from byte-oriented Lua environments where string handling assumes bytes, not UTF-8 text.","solutions":["Fix the Lua script to emit valid UTF-8: hex- or base64-encode binary data before assigning it to a field","Migrate to the v2 Lua transform (`lua` v2) or a remap/VRL transform, which handle bad bytes as errors/lossy instead of panicking","Guard assignments: validate the value is UTF-8 before setting the field, or escape non-ASCII bytes"],"exampleFix":"-- before\nevent[\"payload\"] = chunk  -- chunk may contain non-UTF-8 bytes -> panic\n-- after\nevent[\"payload\"] = chunk:gsub(\"[^\\1-\\127]\", function(b)\n  return string.format(\"\\\\x%02X\", b:byte())\nend)","handlingStrategy":"type-guard","validationCode":"-- Lua: validate before assigning\nevent[\"payload\"] = to_utf8(chunk)","typeGuard":"-- Lua guard for LuaEvent __newindex inputs\nlocal function to_utf8(s)\n  return (s:gsub(\"[^\\1-\\127]\", function(b)\n    return string.format(\"\\\\x%02X\", b:byte())\n  end))\nend","tryCatchPattern":"-- Lua v1: quarantine suspect values instead of panicking the pipeline\nlocal ok, err = pcall(function()\n  event[\"payload\"] = chunk\nend)\nif not ok then\n  event[\"payload_error\"] = tostring(err)\nend","preventionTips":["Never assign raw binary bytes to event fields in Lua v1; hex/base64-encode first","Migrate v1 Lua transforms to lua v2 or remap (VRL), which fail per-event without panicking","Feed binary sources through decode transforms (e.g., base64_decode) before Lua processing"],"tags":["lua","utf-8","transform","bytes","panic"],"backgroundTag":"non-utf8-string","analyzedSha":"3708c39b12a93212ed8b8d7510b4cc7769cb5864","analyzedAt":"2026-08-20T07:02:18.786Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}