1use thiserror::Error;
4
5#[derive(Debug, Error)]
7#[non_exhaustive]
8pub enum ProtocolError {
9 #[error("incomplete packet: expected {expected} bytes, got {actual}")]
11 IncompletePacket {
12 expected: usize,
14 actual: usize,
16 },
17
18 #[error("invalid packet type: {0:#x}")]
20 InvalidPacketType(u8),
21
22 #[error("invalid token type: {0:#x}")]
24 InvalidTokenType(u8),
25
26 #[error("invalid data type: {0:#x}")]
28 InvalidDataType(u8),
29
30 #[error("invalid prelogin option: {0:#x}")]
32 InvalidPreloginOption(u8),
33
34 #[error("invalid TDS version: {0:#x}")]
36 InvalidTdsVersion(u32),
37
38 #[error("string encoding error: {0}")]
40 StringEncoding(
41 #[cfg(feature = "std")] String,
42 #[cfg(not(feature = "std"))] &'static str,
43 ),
44
45 #[error("packet too large: {length} bytes (max {max})")]
47 PacketTooLarge {
48 length: usize,
50 max: usize,
52 },
53
54 #[error("invalid packet status: {0:#x}")]
56 InvalidPacketStatus(u8),
57
58 #[error("buffer overflow: needed {needed} bytes, capacity {capacity}")]
60 BufferOverflow {
61 needed: usize,
63 capacity: usize,
65 },
66
67 #[error("unexpected end of stream")]
69 UnexpectedEof,
70
71 #[error("unsupported protocol version: {0}")]
73 UnsupportedVersion(u32),
74
75 #[error("invalid {field} value: {value}")]
77 InvalidField {
78 field: &'static str,
80 value: u32,
82 },
83}