From 1beb0b14c1d96b27de47917220e45fa708863321 Mon Sep 17 00:00:00 2001 From: Aayush Ojha Date: Fri, 21 Nov 2025 11:52:06 +0530 Subject: [PATCH] Avoid panic on incorrect time format --- src/sources/demo_logs.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/sources/demo_logs.rs b/src/sources/demo_logs.rs index 2fa543353..fdddf367c 100644 --- a/src/sources/demo_logs.rs +++ b/src/sources/demo_logs.rs @@ -21,6 +21,8 @@ use vector_lib::{ EstimatedJsonEncodedSizeOf, }; use vrl::value::Kind; +use std::panic::AssertUnwindSafe; +use std::panic::catch_unwind; use crate::{ codecs::{Decoder, DecodingConfig}, @@ -223,7 +225,14 @@ impl OutputFormat { GenCtx::TimeJoin { data } => { let (time_prefix, time_suffix) = &data[n % data.len()]; let now = Local::now(); - let timestamp = now.format(&time_format).to_string(); + let result = catch_unwind(AssertUnwindSafe(|| now.format(&time_format).to_string())); + let timestamp = match result { + Ok(v) => v, + Err(_) => { + // fallback to rfc3339 format: 2025-11-21T10:25:30.123456789Z + now.to_rfc3339() + } + }; format!("{}{}{}", time_prefix, timestamp, time_suffix) } GenCtx::None => {