{"record":{"id":"41b390482942f1d5","repo":"vectordotdev/vector","slug":"invalid-timestamp","errorCode":null,"errorMessage":"invalid timestamp","messagePattern":"invalid timestamp","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/vector-core/src/event/lua/util.rs","lineNumber":61,"sourceCode":"/// This function will fail if the table is malformed.\n///\n/// # Panics\n///\n/// Panics if the resulting timestamp is invalid.\n#[allow(clippy::needless_pass_by_value)] // constrained by mlua types\npub fn table_to_timestamp(t: LuaTable) -> LuaResult<DateTime<Utc>> {\n    let year = t.raw_get(\"year\")?;\n    let month = t.raw_get(\"month\")?;\n    let day = t.raw_get(\"day\")?;\n    let hour = t.raw_get(\"hour\")?;\n    let min = t.raw_get(\"min\")?;\n    let sec = t.raw_get(\"sec\")?;\n    let nano = t.raw_get::<Option<u32>>(\"nanosec\")?.unwrap_or(0);\n    Ok(Utc\n        .with_ymd_and_hms(year, month, day, hour, min, sec)\n        .single()\n        .and_then(|t| t.with_nanosecond(nano))\n        .expect(\"invalid timestamp\"))\n}\n","sourceCodeStart":43,"sourceCodeEnd":63,"githubUrl":"https://github.com/vectordotdev/vector/blob/3708c39b12a93212ed8b8d7510b4cc7769cb5864/lib/vector-core/src/event/lua/util.rs#L43-L63","documentation":"table_to_timestamp (lib/vector-core/src/event/lua/util.rs) converts a Lua table with year/month/day/hour/min/sec/nanosec fields into a DateTime<Utc> using chrono's with_ymd_and_hms(...).single().expect(\"invalid timestamp\"). If the components do not form a real instant, single() returns None (ambiguous or non-existent, e.g. Feb 30, month 13, hour 25) or with_nanosecond fails on nano > 999,999,999, and the expect panics inside the Lua/wasmtime host function.","triggerScenarios":"A Lua transform (or lua VRL-adjacent host call) returning/constructing a timestamp table with out-of-range or impossible values: month=13, day=31 in a 30-day month, hour=24, min=60, sec=61 (no leap second support), or nanosec >= 1_000_000_000. chrono returns None from .single() (or two values would also be None via single) and the expect fires.","commonSituations":"Lua transform scripts doing date arithmetic by hand (e.g. day = day + 1 rolling past month end), copying 'sec=60' from syslog-style data, parsing timestamps from logs whose fields were never validated, or timezone/DST edge handling done manually in Lua.","solutions":["Clamp and validate components in the Lua script before building the table: 1<=month<=12, day valid for that month/year, hour<=23, min/sec<=59, nanosec<1e9","Do the date math with a proper library: return epoch seconds/float from Lua and construct the timestamp on the Rust side, or use parse_timestamp in VRL instead of hand-built tables","Add a Lua-side guard that returns nil / an error string for impossible dates instead of passing them to the host function"],"exampleFix":"-- before (lua transform)\nlocal ts = { year = y, month = m, day = d + 1, hour = h, min = mi, sec = s }\n\n-- after: normalize via os.time then rebuild\nlocal tmp = os.date(\"*t\", os.time({ year = y, month = m, day = d, hour = h, min = mi, sec = s }) + 86400)\nlocal ts = { year = tmp.year, month = tmp.month, day = tmp.day, hour = tmp.hour, min = tmp.min, sec = tmp.sec }","handlingStrategy":"validation","validationCode":"-- Lua-side guard before building the timestamp table\nlocal function valid_ts(t)\n    return t.month >= 1 and t.month <= 12\n       and t.day >= 1 and t.day <= 31\n       and t.hour >= 0 and t.hour <= 23\n       and t.min >= 0 and t.min <= 59\n       and t.sec >= 0 and t.sec <= 59\n       and (t.nanosec or 0) < 1000000000\nend\nif not valid_ts(ts) then error(\"invalid timestamp components\") end","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never roll dates forward by hand in Lua; use os.time/os.date for arithmetic","Keep sec <= 59 — chrono has no leap-second representation here","nanosec must be < 1_000_000_000","Prefer parse_timestamp/format_timestamp VRL functions over hand-built tables"],"tags":["vector","lua","chrono","timestamp","date-validation","panic"],"backgroundTag":"invalid-timestamp","analyzedSha":"3708c39b12a93212ed8b8d7510b4cc7769cb5864","analyzedAt":"2026-08-20T07:02:18.786Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}