{"record":{"id":"d0488d22dd743d06","repo":"vectordotdev/vector","slug":"could-not-convert-http-status-code-to-json","errorCode":null,"errorMessage":"Could not convert HTTP status code to JSON","messagePattern":"Could not convert HTTP status code to JSON","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/vector-config/src/http.rs","lineNumber":15,"sourceCode":"use std::cell::RefCell;\n\nuse http::StatusCode;\nuse serde_json::Value;\nuse vector_config_common::{attributes::CustomAttribute, constants};\n\nuse crate::{\n    Configurable, GenerateError, Metadata, ToValue,\n    num::NumberClass,\n    schema::{SchemaGenerator, SchemaObject, generate_number_schema},\n};\n\nimpl ToValue for StatusCode {\n    fn to_value(&self) -> Value {\n        serde_json::to_value(self.as_u16()).expect(\"Could not convert HTTP status code to JSON\")\n    }\n}\n\nimpl Configurable for StatusCode {\n    fn referenceable_name() -> Option<&'static str> {\n        Some(\"http::StatusCode\")\n    }\n\n    fn is_optional() -> bool {\n        true\n    }\n\n    fn metadata() -> Metadata {\n        let mut metadata = Metadata::default();\n        metadata.set_description(\"HTTP response status code\");\n        metadata.add_custom_attribute(CustomAttribute::kv(\n            constants::DOCS_META_NUMERIC_TYPE,\n            NumberClass::Unsigned,","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/lib/vector-config/src/http.rs#L1-L33","documentation":"vector-config implements `ToValue for http::StatusCode` by serializing `self.as_u16()` to JSON, panicking with \"Could not convert HTTP status code to JSON\" if serde_json rejects it. A u16 is always JSON-serializable in principle, so a panic here means serde_json itself refused a valid number (practically impossible, indicating a corrupted serde_json state or an unexpected serialization hook). It is a defensive invariant panic in schema generation.","triggerScenarios":"Calling `StatusCode::to_value()` during config schema generation when serde_json::to_value returns Err for a u16 — an effectively unreachable path kept as a guard against serde_json misconfiguration (e.g. arbitrary_precision mode incompatibilities in some versions).","commonSituations":"Generating schemas for HTTP-related component configs that include StatusCode fields; encountering this usually points to a serde_json feature mismatch in the build (e.g. conflicting arbitrary_precision settings).","solutions":["Verify serde_json features are consistent across the workspace (arbitrary_precision can change number serialization behavior)","Rebuild with a single unified serde_json version to avoid feature unification surprises","If patching, serialize with serde_json::json!(self.as_u16()) which cannot fail for u16"],"exampleFix":"// before\nserde_json::to_value(self.as_u16()).expect(\"Could not convert HTTP status code to JSON\")\n// after\nserde_json::Value::Number(serde_json::Number::from(self.as_u16()))","handlingStrategy":"validation","validationCode":"// u16 is always JSON-safe; validate the source value instead:\nlet code: u16 = status_code.as_u16();\ndebug_assert!(serde_json::to_value(code).is_ok());","typeGuard":"fn is_serializable_status(s: &http::StatusCode) -> bool {\n    serde_json::to_value(s.as_u16()).is_ok()\n}","tryCatchPattern":"// bypass the panicking impl entirely:\nlet v = serde_json::json!(status_code.as_u16());","preventionTips":["Ensure serde_json features are consistent workspace-wide (beware arbitrary_precision)","Prefer serde_json::Value::Number::from(u16) for infallible construction","Rebuild after dependency bumps to clear feature-unification mismatches"],"tags":["rust","http","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"}