{"record":{"id":"78fbf5f56a7000c3","repo":"databendlabs/databend","slug":"expected-to-have-bytes","errorCode":null,"errorMessage":"Expected to have bytes {:?}","messagePattern":"Expected to have bytes (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/common/io/src/cursor_ext/cursor_read_bytes_ext.rs","lineNumber":49,"sourceCode":"    fn until(&mut self, delim: u8, buf: &mut Vec<u8>) -> usize;\n    fn keep_read(&mut self, buf: &mut Vec<u8>, f: impl Fn(u8) -> bool) -> usize;\n    fn eof(&mut self) -> bool;\n    fn must_eof(&mut self) -> Result<()>;\n    fn must_ignore(&mut self, f: impl Fn(u8) -> bool) -> Result<()> {\n        if !self.ignore(f) {\n            return Err(std::io::Error::new(\n                ErrorKind::InvalidData,\n                \"Expected to ignore a byte\",\n            ));\n        }\n        Ok(())\n    }\n\n    fn must_ignore_byte(&mut self, b: u8) -> Result<()>;\n\n    fn must_ignore_bytes(&mut self, bs: &[u8]) -> Result<()> {\n        if !self.ignore_bytes(bs) {\n            return Err(std::io::Error::new(\n                ErrorKind::InvalidData,\n                format!(\"Expected to have bytes {:?}\", bs),\n            ));\n        }\n        Ok(())\n    }\n\n    fn must_ignore_insensitive_bytes(&mut self, bs: &[u8]) -> Result<()> {\n        if !self.ignore_insensitive_bytes(bs) {\n            return Err(std::io::Error::new(\n                ErrorKind::InvalidData,\n                format!(\"Expected to have insensitive bytes {:?}\", bs),\n            ));\n        }\n        Ok(())\n    }\n}\n","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/common/io/src/cursor_ext/cursor_read_bytes_ext.rs#L31-L67","documentation":"CursorReadBytesExt::must_ignore_bytes consumes bs.len() bytes from the cursor if they exactly match bs. If the cursor does not hold those bytes (mismatch or EOF), it fails with an InvalidData io error that embeds the expected byte sequence for debugging.","triggerScenarios":"Calling must_ignore_bytes(bs) when the upcoming bytes differ from bs or fewer than bs.len() bytes remain.","commonSituations":"Validating magic numbers, version tags, or fixed prefixes in binary formats when parsing misaligned, wrong-version, or truncated data.","solutions":["Compare the error's {:?} bytes with the actual data at the cursor position to find the mismatch.","Use ignore_bytes(bs) if the prefix is optional or may vary.","Check the producer/writer emits the exact expected byte sequence (endianness, encoding)."],"exampleFix":"// before\ncursor.must_ignore_bytes(b\"MAGIC\")?;\n\n// after\nif !cursor.ignore_bytes(b\"MAGIC\") {\n    return Err(anyhow!(\"unexpected file header\"));\n}","handlingStrategy":"validation","validationCode":"if remaining_bytes(cursor) < expected.len() || !starts_with(cursor, expected) {\n    return Err(anyhow!(\"unexpected prefix\"));\n}","typeGuard":null,"tryCatchPattern":"if !cursor.ignore_bytes(b\"MAGIC\") {\n    return Err(anyhow!(\"not the expected file format\"));\n}","preventionTips":["Check magic/version bytes before calling must_* methods.","Use ignore_bytes for optional prefixes.","Verify producer endianness/encoding matches the parser's expectations."],"tags":["parsing","io","rust","cursor"],"backgroundTag":"invalid-argument-format","analyzedSha":"288d84d76e20a2f8f7173bda9691eb6ece301aa9","analyzedAt":"2026-09-11T11:29:36.208Z","contentChangedAt":"2026-09-11T11:29:36.208Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}