{"record":{"id":"fe4feabce088b7dc","repo":"vectordotdev/vector","slug":"could-not-convert-time-zone-to-json","errorCode":null,"errorMessage":"Could not convert time zone to JSON","messagePattern":"Could not convert time zone to JSON","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/vector-config/src/external/datetime.rs","lineNumber":69,"sourceCode":"        apply_metadata(&mut local_schema, local_metadata);\n\n        let mut tz_metadata = Metadata::with_title(\"A named timezone.\");\n        tz_metadata.set_description(\n            r#\"Must be a valid name in the [TZ database][tzdb].\n\n[tzdb]: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones\"#,\n        );\n        tz_metadata.add_custom_attribute(CustomAttribute::kv(\"logical_name\", \"Named\"));\n        let tz_schema =\n            get_or_generate_schema(&Tz::as_configurable_ref(), generator, Some(tz_metadata))?;\n\n        Ok(generate_one_of_schema(&[local_schema, tz_schema]))\n    }\n}\n\nimpl ToValue for TimeZone {\n    fn to_value(&self) -> Value {\n        serde_json::to_value(self).expect(\"Could not convert time zone to JSON\")\n    }\n}\n","sourceCodeStart":51,"sourceCodeEnd":72,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/lib/vector-config/src/external/datetime.rs#L51-L72","documentation":"In vector-config's schema generation, `TimeZone`'s `ToValue` impl converts the time zone into a JSON `Value` via serde_json and panics with \"Could not convert time zone to JSON\" if serialization fails. Time zones are expected to always be JSON-serializable (as an IANA string), so failure signals a genuinely unexpected state. Because `to_value` returns `Value` (not Result), the failure is a panic rather than an error return.","triggerScenarios":"Calling `TimeZone::to_value()` during config schema generation or metadata extraction when serde_json cannot serialize the TimeZone's serde representation.","commonSituations":"Building schema/config metadata for components whose config includes chrono time zones; effectively never hit in practice — usually only when a custom serialization override or unusual TimeZone payload breaks the invariant.","solutions":["Inspect the TimeZone value being serialized (custom serde impls or wrappers can break JSON representability)","Ensure no custom Serialize impl for TimeZone writes non-JSON-compatible data (e.g. maps with non-string keys)","Replace the expect with error propagation if your wrapper allows returning a Result"],"exampleFix":"// before\nserde_json::to_value(self).expect(\"Could not convert time zone to JSON\")\n// after\nserde_json::to_value(self).unwrap_or(serde_json::Value::String(self.to_string()))","handlingStrategy":"type-guard","validationCode":"// Confirm serializability before to_value:\nserde_json::to_value(&tz).map_err(|e| eprintln!(\"timezone not JSON-serializable: {e}\")).ok();","typeGuard":"fn is_json_safe<T: serde::Serialize>(v: &T) -> bool { serde_json::to_value(v).is_ok() }","tryCatchPattern":"// to_value panics; isolate calls:\nlet result = std::panic::catch_unwind(|| tz.to_value());","preventionTips":["Avoid overriding Serialize for TimeZone wrappers","Keep chrono/tz crate versions aligned across the workspace","Test schema generation on configs containing timezone fields"],"tags":["rust","serialization","json","panic","timezone"],"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"}