{"record":{"id":"907477b74c87f7ca","repo":"vectordotdev/vector","slug":"functiondoc-serialization-should-not-fail","errorCode":null,"errorMessage":"FunctionDoc serialization should not fail","messagePattern":"FunctionDoc serialization should not fail","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/vector-vrl/doc-builder/src/main.rs","lineNumber":38,"sourceCode":"    minify: bool,\n\n    /// File extension for generated files (directory mode only)\n    #[arg(short, long, default_value = \"json\", requires = \"output\")]\n    extension: String,\n}\n\n#[allow(clippy::print_stdout)]\nfn main() -> Result<()> {\n    let cli = <Cli as clap::Parser>::parse();\n    let functions = vector_vrl_functions::all_without_vrl_stdlib();\n    if let Some(output) = &cli.output {\n        document_functions_to_dir(&functions, output, &cli.extension)?;\n    } else {\n        let built = build_functions_doc(&functions);\n        if cli.minify {\n            println!(\n                \"{}\",\n                serde_json::to_string(&built).expect(\"FunctionDoc serialization should not fail\")\n            );\n        } else {\n            println!(\n                \"{}\",\n                serde_json::to_string_pretty(&built)\n                    .expect(\"FunctionDoc serialization should not fail\")\n            );\n        }\n    }\n    Ok(())\n}\n","sourceCodeStart":20,"sourceCodeEnd":50,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/lib/vector-vrl/doc-builder/src/main.rs#L20-L50","documentation":"The vrl doc-builder CLI converts VRL function docs into a `FunctionDoc` structure and serializes it to JSON with `serde_json::to_string`, panicking with this message on failure. JSON serialization of this plain-data struct is expected to be infallible; the panic guards against a serde bug or an unserializable field type sneaking in.","triggerScenarios":"Running `doc-builder` without `--minify` (pretty variant at line 38 uses to_string; this is the minified `to_string` path) when `serde_json::to_string(&built)` returns Err — e.g. a `FunctionDoc` field containing a map with non-string keys or a NaN float introduced by a new function definition.","commonSituations":"Adding a new VRL function whose docs contain data serde_json cannot serialize (odd key types, non-finite floats); serde version mismatches in the workspace.","solutions":["Inspect the newly added/changed function docs (doc comments/args) for values that fail JSON serialization (NaN/Inf floats, non-string map keys)","Run the builder with RUST_BACKTRACE=1 to confirm which field fails, or temporarily replace expect with a match to print the serde error","Ensure serde/serde_json versions are consistent across the workspace (`cargo update`)","If a doc field is genuinely fallible, change `FunctionDoc` to serialize via a fallible path and propagate the error with `?`"],"exampleFix":"// before\nserde_json::to_string(&built).expect(\"FunctionDoc serialization should not fail\")\n// after\nserde_json::to_string(&built)\n    .context(\"FunctionDoc serialization should not fail\")?","handlingStrategy":"try-catch","validationCode":"let json = serde_json::to_string(&built);\nassert!(json.is_ok(), \"FunctionDoc must be JSON-serializable: {:?}\", json.err());","typeGuard":"fn is_finite_doc_value(v: &serde_json::Value) -> bool {\n    match v { serde_json::Value::Number(n) => n.is_finite(), _ => true }\n}","tryCatchPattern":"match serde_json::to_string(&built) {\n    Ok(s) => println!(\"{s}\"),\n    Err(e) => eprintln!(\"doc serialization failed: {e}\"), // surface real cause\n}","preventionTips":["When adding VRL functions, keep doc fields to JSON-safe types (strings, finite numbers)","Add a unit test that serializes the built FunctionDoc for every function","Keep serde/serde_json versions aligned across the workspace"],"tags":["rust","cli","json","serde"],"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"}