tds_protocol/
error.rs

1//! Protocol-level error types.
2
3use thiserror::Error;
4
5/// Errors that can occur during TDS protocol parsing or encoding.
6#[derive(Debug, Error)]
7pub enum ProtocolError {
8    /// Packet data is truncated or incomplete.
9    #[error("incomplete packet: expected {expected} bytes, got {actual}")]
10    IncompletePacket {
11        /// Expected number of bytes.
12        expected: usize,
13        /// Actual number of bytes available.
14        actual: usize,
15    },
16
17    /// Invalid packet type value.
18    #[error("invalid packet type: {0:#x}")]
19    InvalidPacketType(u8),
20
21    /// Invalid token type value.
22    #[error("invalid token type: {0:#x}")]
23    InvalidTokenType(u8),
24
25    /// Invalid data type value.
26    #[error("invalid data type: {0:#x}")]
27    InvalidDataType(u8),
28
29    /// Invalid prelogin option.
30    #[error("invalid prelogin option: {0:#x}")]
31    InvalidPreloginOption(u8),
32
33    /// Invalid TDS version.
34    #[error("invalid TDS version: {0:#x}")]
35    InvalidTdsVersion(u32),
36
37    /// String encoding error.
38    #[error("string encoding error: {0}")]
39    StringEncoding(
40        #[cfg(feature = "std")] String,
41        #[cfg(not(feature = "std"))] &'static str,
42    ),
43
44    /// Packet length exceeds maximum allowed.
45    #[error("packet too large: {length} bytes (max {max})")]
46    PacketTooLarge {
47        /// Actual packet length.
48        length: usize,
49        /// Maximum allowed length.
50        max: usize,
51    },
52
53    /// Invalid packet status flags.
54    #[error("invalid packet status: {0:#x}")]
55    InvalidPacketStatus(u8),
56
57    /// Buffer overflow during encoding.
58    #[error("buffer overflow: needed {needed} bytes, capacity {capacity}")]
59    BufferOverflow {
60        /// Bytes needed.
61        needed: usize,
62        /// Buffer capacity.
63        capacity: usize,
64    },
65
66    /// Unexpected end of stream.
67    #[error("unexpected end of stream")]
68    UnexpectedEof,
69
70    /// Protocol version mismatch.
71    #[error("unsupported protocol version: {0}")]
72    UnsupportedVersion(u32),
73}