{"record":{"id":"051f6a34baa5dbc0","repo":"nautechsystems/nautilus_trader","slug":"failed-to-read-record-e","errorCode":null,"errorMessage":"Failed to read record: {e}","messagePattern":"Failed to read record: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/tardis/src/csv/stream.rs","lineNumber":303,"sourceCode":"            // Only set F_LAST when limit reached (stream ending), not on chunk\n            // boundary where more deltas from the same message may follow\n            if let Some(limit) = self.limit\n                && self.deltas_emitted >= limit\n                && let Some(last_delta) = self.buffer.last_mut()\n            {\n                last_delta.flags = RecordFlag::F_LAST as u8;\n            }\n            Some(Ok(self.buffer.clone()))\n        }\n    }\n}\n\nimpl DeltaStreamIterator {\n    fn read_record(&mut self) -> anyhow::Result<Option<TardisBookUpdateRecord>> {\n        if !self\n            .reader\n            .read_record(&mut self.record)\n            .map_err(|e| anyhow::anyhow!(\"Failed to read record: {e}\"))?\n        {\n            return Ok(None);\n        }\n\n        self.record\n            .deserialize::<TardisBookUpdateRecord>(None)\n            .map(Some)\n            .map_err(|e| anyhow::anyhow!(\"Failed to deserialize record: {e}\"))\n    }\n}\n\n/// Streams [`OrderBookDelta`]s from a Tardis format CSV at the given `filepath`,\n/// yielding chunks of the specified size.\n///\n/// # Precision Inference Warning\n///\n/// When using streaming with precision inference (not providing explicit precisions),\n/// the inferred precision may differ from bulk loading the entire file. This is because","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/tardis/src/csv/stream.rs#L285-L321","documentation":"`DeltaStreamIterator::read_record` reads raw CSV rows via the csv reader. If the underlying reader returns an I/O or CSV parsing error, it is wrapped in this error rather than being silently dropped, so the streaming consumer can surface the failure. It indicates the file could not be read at the record level — distinct from deserialization failures of an otherwise readable row.","triggerScenarios":"Iterating a `DeltaStream` whose `next` calls `read_record` while the CSV file is unreadable, deleted mid-read, on a failing disk/network mount, malformed at the byte level (e.g. wrong quoting/delimiter so the csv crate errors), or not valid UTF-8.","commonSituations":"Reading a file over an unstable network share; a truncated download; a file written with a different delimiter or quoting convention than the csv reader expects.","solutions":["Verify the file path exists and is readable: `ls -l`, check permissions, and re-test locally.","Re-download or re-export the CSV; check for truncation or corruption (compare file size/checksum with the source).","Confirm the file is standard comma-separated UTF-8 CSV as produced by Tardis Machine; re-export if quoting or encoding differs.","Retry the read if the file lives on a flaky network mount."],"exampleFix":"// before\nlet stream = DeltaStream::from_path(\"/mnt/net/tardis.csv\", ...)?; // flaky mount\n// after: verify and fail fast before streaming\nlet file = std::fs::File::open(\"/mnt/net/tardis.csv\")?;\nlet len = file.metadata()?.len();\nassert!(len > 0, \"CSV truncated\");\nlet stream = DeltaStream::from_path(\"/mnt/net/tardis.csv\", ...)?;","handlingStrategy":"validation","validationCode":"from pathlib import Path\n\ndef ensure_readable_csv(path: str) -> None:\n    p = Path(path)\n    if not p.is_file():\n        raise FileNotFoundError(path)\n    if p.stat().st_size == 0:\n        raise ValueError(f\"{path} is empty (truncated download?)\")\n    with open(p, \"rb\") as f:\n        f.read(1024).decode(\"utf-8\")  # raises on invalid encoding","typeGuard":"def is_readable_csv(path: str) -> bool:\n    from pathlib import Path\n    p = Path(path)\n    return p.is_file() and p.stat().st_size > 0","tryCatchPattern":"try:\n    for batch in stream:\n        process(batch)\nexcept Exception as e:\n    if \"Failed to read record\" in str(e):\n        # I/O-level failure: verify file, re-download, retry once from local copy\n        local = stage_local(path)\n        retry_stream(local)\n    else:\n        raise","preventionTips":["Stage files on local disk before long streaming runs instead of reading network mounts","Verify file size/checksum after download; never stream a partially written file","Exclude data directories from cleanup/rotation jobs during reads"],"tags":["rust","csv","io","file-read"],"backgroundTag":"file-read-failed","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}