{"record":{"id":"554d16e3e874f126","repo":"valeriansaliou/sonic","slug":"invaliddata","errorCode":null,"errorMessage":"InvalidData","messagePattern":"InvalidData","errorType":"exception","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"client/src/util.rs","lineNumber":11,"sourceCode":"// Sonic\n//\n// Fast, lightweight and schema-less search backend\n// Copyright: 2026, Rémi Bardon <remi@remibardon.name>\n// License: Mozilla Public License v2.0 (MPL v2.0)\n\npub(crate) mod errors {\n    pub fn io_error_invalid_data<E: Into<Box<dyn std::error::Error + Send + Sync>>>(\n        error: E,\n    ) -> std::io::Error {\n        std::io::Error::new(std::io::ErrorKind::InvalidData, error)\n    }\n}\n\n/// Builds a command String efficiently.\n#[cfg_attr(feature = \"raw-api\", macro_export)]\nmacro_rules! make_command {\n    ($command:literal) => {{\n        $crate::Command::from($command)\n    }};\n\n    ($format:literal $(, $arg:ident)* $(; text: $text:ident)? $(; options: $options:ident)?) => {{\n        use std::fmt::Write as _;\n\n        $(let $arg: &str = $arg.as_ref();)*\n        $(let $text: &str = $text.as_ref();)?\n\n        // NOTE: Since we can’t know if the argument will be quoted or not,\n        //   this macro is a bit too generic and might waste a few bytes of","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/valeriansaliou/sonic/blob/e6a72da6a532bc3f31d7d93ef1e0964a1a5d01b2/client/src/util.rs#L1-L29","documentation":"io_error_invalid_data is the library's helper that wraps any parse/conversion failure into std::io::Error with ErrorKind::InvalidData. It is used by parse_line, connect, parse and FromStr implementations when a server reply or configured value cannot be decoded into the expected type. The inner error carries the concrete cause.","triggerScenarios":"Calling any typed command whose response fails to parse (parse_line/parse), constructing a connection via connect with malformed input, or parsing a value with the type's FromStr impl when the text does not match the expected format.","commonSituations":"Server/client version mismatch producing unexpected reply formats; reading a value written as one type and parsed as another; corrupted or truncated line-oriented responses; whitespace/encoding differences in server output.","solutions":["Inspect the error's source/inner payload to see the exact parse failure and raw input.","Confirm client and server protocol versions match.","Parse with the correct target type; e.g. don't FromStr an integer field into a float-only format.","Log raw responses (raw-api feature) to identify format deviations before parsing."],"exampleFix":"// before\nlet n: u64 = value.parse()?; // opaque InvalidData on bad input\n// after\nlet n: u64 = value.parse().map_err(|e| {\n    eprintln!(\"failed to parse {:?} as u64: {}\", value, e);\n    e\n})?;","handlingStrategy":"validation","validationCode":"fn parse_u64_field(raw: &str) -> std::io::Result<u64> {\n    raw.trim().parse::<u64>().map_err(|e|\n        std::io::Error::new(\n            std::io::ErrorKind::InvalidData,\n            format!(\"unexpected field {:?}: {}\", raw, e),\n        )\n    )\n}","typeGuard":"fn is_invalid_data(e: &std::io::Error) -> bool {\n    e.kind() == std::io::ErrorKind::InvalidData\n}","tryCatchPattern":"match channel.get(\"counter\").await {\n    Err(e) if e.kind() == std::io::ErrorKind::InvalidData => {\n        // inspect e.get_ref() / e.source() for the raw failing payload\n        log::error!(\"unparsable response: {}\", e);\n    }\n    other => other?,\n}","preventionTips":["Pin matching client/server versions to keep reply formats in sync","Inspect the error's inner source to learn the exact parse failure","Validate data types at write time so reads parse predictably","Log raw responses when debugging unexpected InvalidData"],"tags":["invalid-data","parsing","io","rust"],"backgroundTag":"response-parse-failed","analyzedSha":"e6a72da6a532bc3f31d7d93ef1e0964a1a5d01b2","analyzedAt":"2026-09-01T14:10:00.384Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T20:17:18.057Z"}