{"record":{"id":"819598b85a17c8a0","repo":"nautechsystems/nautilus_trader","slug":"invalid-uuid4-bytes-length","errorCode":null,"errorMessage":"Invalid UUID4 bytes length","messagePattern":"Invalid UUID4 bytes length","errorType":"exception","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"crates/serialization/src/capnp/conversions.rs","lineNumber":159,"sourceCode":"    }\n    Ok(map)\n}\n\nimpl<'a> ToCapnp<'a> for nautilus_core::UUID4 {\n    type Builder = base_capnp::u_u_i_d4::Builder<'a>;\n\n    fn to_capnp(&self, mut builder: Self::Builder) {\n        builder.set_value(&self.as_bytes());\n    }\n}\n\nimpl<'a> FromCapnp<'a> for nautilus_core::UUID4 {\n    type Reader = base_capnp::u_u_i_d4::Reader<'a>;\n\n    fn from_capnp(reader: Self::Reader) -> Result<Self, Box<dyn Error>> {\n        let bytes = reader.get_value()?;\n        let bytes_array: [u8; 16] = bytes.try_into().map_err(|_| {\n            std::io::Error::new(\n                std::io::ErrorKind::InvalidData,\n                \"Invalid UUID4 bytes length\",\n            )\n        })?;\n        let uuid = Uuid::from_bytes(bytes_array);\n        Ok(Self::from(uuid))\n    }\n}\n\n// Decimal\n// rust_decimal serialization format (16 bytes):\n// - Bytes 0-3: flags (u32) - scale and sign\n// - Bytes 4-7: lo (u32) - low 32 bits of coefficient\n// - Bytes 8-11: mid (u32) - middle 32 bits of coefficient\n// - Bytes 12-15: hi (u32) - high 32 bits of coefficient\nfn decimal_to_parts(value: &Decimal) -> (u64, u64, u64, u32) {\n    let bytes = value.serialize();\n    let flags = u32::from_le_bytes(bytes[0..4].try_into().expect(\"flags slice\"));","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/serialization/src/capnp/conversions.rs#L141-L177","documentation":"Cap'n Proto decoding of a UUID4 expects the message field to carry exactly 16 raw bytes. The reader's value is converted via try_into() into a [u8; 16]; any other byte length fails conversion, and this InvalidData Io error is returned inside Box<dyn Error> from from_capnp, meaning the incoming payload's UUID field is corrupt or written by an incompatible schema/version.","triggerScenarios":"Calling UUID4::from_capnp on a base_capnp::u_u_i_d4::Reader whose value buffer is not 16 bytes long — e.g. a peer serializing a UUID string, a truncated message, or a schema version writing a different byte-width field.","commonSituations":"Deserializing messages produced by a different nautilus version or another implementation with a mismatched capnp schema; corrupted or truncated transport frames; manually constructed capnp messages with hex-string UUIDs instead of 16 raw bytes.","solutions":["Fix the producer so it writes the UUID as exactly 16 raw bytes via uuid.as_bytes() before encoding into the capnp field.","Verify both sides use the same generated capnp schema (cargo build regenerates from the same .capnp files).","Inspect the offending message's raw payload length to find truncation at the transport layer.","Reject/replicate or drop malformed messages at the receive loop so one bad frame does not break the stream."],"exampleFix":"// before (producer)\nbuilder.set_value(uuid.to_string().as_bytes());\n// after (producer)\nbuilder.set_value(uuid.as_bytes()); // &[u8; 16]","handlingStrategy":"try-catch","validationCode":"if reader.get_value()?.len() != 16 {\n    return Err(\"capnp UUID4 field must be exactly 16 bytes\".into());\n}","typeGuard":"fn is_uuid4_bytes(b: &[u8]) -> bool { b.len() == 16 }","tryCatchPattern":"match UUID4::from_capnp(reader) {\n    Ok(uuid) => uuid,\n    Err(e) => { log::error!(\"bad UUID4 field: {e}\"); continue; } // skip malformed frame\n}","preventionTips":["Always serialize UUIDs with uuid.as_bytes() (16 bytes), never as strings.","Keep both peers on the same generated capnp schema version.","Frame-check message lengths at the transport layer to catch truncation early."],"tags":["capnp","deserialization","uuid","rust"],"backgroundTag":"schema-validation-failed","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}