{"record":{"id":"05e38aab9fba5dd0","repo":"vectordotdev/vector","slug":"mod","errorCode":null,"errorMessage":"{}","messagePattern":"\\{\\}","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/sinks/file/mod.rs","lineNumber":774,"sourceCode":"        opts.custom_flags(libc::O_NOFOLLOW);\n    }\n    #[cfg(not(unix))]\n    let _ = confined;\n\n    opts.open(open_path).await.map_err(OpenError::Io)\n}\n\nasync fn write_event_to_file(\n    file: &mut OutFile,\n    mut event: Event,\n    transformer: &Transformer,\n    encoder: &mut Encoder<Framer>,\n) -> Result<usize, std::io::Error> {\n    transformer.transform(&mut event);\n    let mut buffer = BytesMut::new();\n    encoder\n        .encode(event, &mut buffer)\n        .map_err(|error| std::io::Error::new(std::io::ErrorKind::InvalidData, error))?;\n    file.write_all(&buffer).await.map(|()| buffer.len())\n}\n\n#[async_trait]\nimpl StreamSink<Event> for FileSink {\n    async fn run(mut self: Box<Self>, input: BoxStream<'_, Event>) -> Result<(), ()> {\n        FileSink::run(&mut self, input)\n            .await\n            .expect(\"file sink error\");\n        Ok(())\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use std::convert::TryInto;\n\n    use chrono::{SubsecRound, Utc};","sourceCodeStart":756,"sourceCodeEnd":792,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/src/sinks/file/mod.rs#L756-L792","documentation":"`write_event_to_file` encodes each event with the configured framer/encoder; encoding failures (events that don't fit the configured codec, e.g. non-UTF8 or schema-invalid payloads) are converted into `io::ErrorKind::InvalidData` io::Errors, which abort the file sink stream.","triggerScenarios":"The event fails encoding per the sink's `encoding` config — e.g. feeding non-JSON-serializable values to json encoding, invalid UTF-8 for text encoding, or Avro schema violations.","commonSituations":"Encoding misconfiguration on the file sink (text vs json vs native_json), events containing malformed/unsupported values after VRL transforms, or framing incompatibilities.","solutions":["Check the sink's `encoding` setting matches your data (e.g. use `native_json` or `json` instead of `text` for non-string events).","Add a VRL transform to sanitize/drop events that cannot be encoded.","Inspect the wrapped inner error message to find the offending event shape/field.","Route problematic events to a fallback sink via `remap` with a conditional drop."],"exampleFix":"# before\nencoding:\n  codec: text   # fails on non-string events\n\n# after\nencoding:\n  codec: json   # encodes structured events\ntransform:\n  type: remap\n  source: '._ = string!(.message)' # normalize payload","handlingStrategy":"validation","validationCode":"// validate events are encodable per the sink codec before writing\nif encoding == \"text\" {\n    let _ = event.as_string().ok_or(\"file sink text encoding requires string events\")?;\n}","typeGuard":"fn encodable(e: &Event, codec: &str) -> bool {\n    codec != \"text\" || matches!(e, Event::Log(l) if l.get(\"message\").map_or(false, |v| v.is_bytes()))\n}","tryCatchPattern":"match encoder.encode(&mut event, &mut buffer) {\n    Err(e) => {\n        error!(message = \"Failed to encode file sink event\", %e);\n        // drop/reroute the event instead of failing the whole stream\n    }\n    Ok(_) => {},\n}","preventionTips":["Match the sink encoding codec to your event shape.","Use a remap transform to normalize/drop unencodable events upstream.","Check log warnings from the file sink for the first failing event."],"tags":["file-sink","encoding","io","serialization"],"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"}