{"record":{"id":"756be37e21cbf040","repo":"nautechsystems/nautilus_trader","slug":"buffer-too-short-for-field-expected-expected-l","errorCode":null,"errorMessage":"Buffer too short for {field}: expected {expected_len}, was {}","messagePattern":"Buffer too short for (.+?): expected (.+?), was (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/spot/websocket/trading/decode_sbe.rs","lineNumber":116,"sourceCode":"    if data.len() < min_len {\n        anyhow::bail!(\n            \"Buffer too short for fixed block: expected {min_len}, was {}\",\n            data.len()\n        );\n    }\n\n    let mut field_offset = min_len;\n    for field in EXECUTION_REPORT_VAR_DATA_FIELDS {\n        let Some(length) = data.get(field_offset) else {\n            anyhow::bail!(\n                \"Buffer too short for {field} length: expected {}, was {}\",\n                field_offset + 1,\n                data.len()\n            );\n        };\n        let expected_len = field_offset + 1 + usize::from(*length);\n        if data.len() < expected_len {\n            anyhow::bail!(\n                \"Buffer too short for {field}: expected {expected_len}, was {}\",\n                data.len()\n            );\n        }\n        field_offset = expected_len;\n    }\n\n    let mut dec = execution_report_event_codec::ExecutionReportEventDecoder::default().wrap(\n        buf,\n        HEADER_LEN,\n        block_length,\n        version,\n    );\n\n    let price_exp = dec.price_exponent();\n    let qty_exp = dec.qty_exponent();\n    let commission_exp = dec.commission_exponent();\n","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/spot/websocket/trading/decode_sbe.rs#L98-L134","documentation":"Each variable-length field in the ExecutionReportEvent is a 1-byte length followed by that many bytes. This error fires when a field's length byte was read but the buffer ends before the field's full data, i.e. data.len() < field_offset + 1 + length. The decoder bails rather than decoding a short string.","triggerScenarios":"Calling decode_execution_report with a frame whose trailing variable-length section is cut mid-field — e.g. a symbol advertised as 6 bytes but only 3 present; truncated network message or truncated capture.","commonSituations":"Network/truncation issues splitting SBE frames; binary fixtures clipped at a byte boundary; corruption when persisting or replaying captured messages.","solutions":["Ensure the entire frame is delivered before decoding (complete WebSocket reassembly)","Re-encode the message with execution_report_event_codec to regenerate a consistent buffer","Validate frame completeness (checksum or length accounting) upstream","Fix capture/replay tooling that clips the final bytes"],"exampleFix":"// before\nlet frame = &captured[..captured.len() - 2]; // accidental clip\nlet report = decode_execution_report(frame)?;\n// after\nlet report = decode_execution_report(captured)?; // full frame preserved","handlingStrategy":"validation","validationCode":"pub fn var_fields_intact(data: &[u8]) -> bool {\n    if data.len() < 8 { return false; }\n    let block_length = u16::from_be_bytes([data[0], data[1]]) as usize;\n    let mut off = 8 + block_length;\n    for _ in 0..6 {\n        let Some(&len) = data.get(off) else { return false };\n        off += 1 + len as usize;\n    }\n    off <= data.len()\n}","typeGuard":"fn intact_var_section<'a>(data: &'a [u8]) -> Option<&'a [u8]> {\n    var_fields_intact(data).then_some(data)\n}","tryCatchPattern":"match decode_execution_report(&frame) {\n    Ok(r) => handle(r),\n    Err(e) if e.to_string().contains(\"Buffer too short\") => {\n        log::debug!(\"dropping truncated frame ({} bytes)\", frame.len());\n    }\n    Err(e) => log::warn!(\"SBE decode failed: {e}\"),\n}","preventionTips":["Verify end-to-end frame length accounting before decode","Use checksums or length prefixes when storing/replaying captures","Avoid slicing captures at arbitrary byte offsets","Fail loudly on truncation so transport bugs surface in testing"],"tags":["sbe","binance","buffer","truncated"],"backgroundTag":"invalid-argument-format","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"}