use thiserror::Error;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum ProtocolError {
#[error("unexpected end of buffer: needed {needed} more bytes")]
UnexpectedEof { needed: usize },
#[error("invalid value: {0}")]
InvalidValue(&'static str),
#[error("invalid UTF-8 in string field")]
InvalidUtf8(#[source] std::str::Utf8Error),
#[error("varint exceeds {max} bytes")]
VarintTooLong { max: usize },
#[error("unsupported API version {version} for api key {api_key}")]
UnsupportedVersion { api_key: i16, version: i16 },
#[error("schema mismatch: {0}")]
SchemaMismatch(&'static str),
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn display_is_useful() {
let e = ProtocolError::UnexpectedEof { needed: 4 };
assert_eq!(
e.to_string(),
"unexpected end of buffer: needed 4 more bytes"
);
}
}