Skip to main content

arks_protocol/
error.rs

1//! pkt-line and capability-helper errors.
2
3/// Failure while encoding or decoding a claimed protocol helper.
4#[derive(Debug, thiserror::Error, PartialEq, Eq)]
5pub enum ProtocolError {
6    /// Input ended before a 4-byte length or before `pkt-len` payload bytes.
7    #[error("pkt-line truncated")]
8    Truncated,
9    /// Length field is not four lowercase hex digits (`0-9a-f`).
10    ///
11    /// gitprotocol-common replaces ABNF `HEXDIG` with `DIGIT / "a" / … / "f"`.
12    #[error("pkt-len is not 4 lowercase hex digits")]
13    BadHexLength,
14    /// `0003` is neither a data pkt-line (`pkt-len >= 4`) nor a documented special.
15    ///
16    /// Specials are flush `0000` (gitprotocol-common), delim `0001`, and
17    /// response-end `0002` (gitprotocol-v2).
18    #[error("reserved pkt-len {pkt_len:#06x}")]
19    ReservedLength { pkt_len: u16 },
20    /// Encoded data payload exceeds 65516 bytes (gitprotocol-common).
21    #[error("payload length {len} exceeds maximum {max}")]
22    PayloadTooLarge { len: usize, max: usize },
23    /// Decoded `pkt-len` exceeds 65520 (gitprotocol-common).
24    #[error("pkt-len {pkt_len} exceeds maximum {max}")]
25    LineTooLong { pkt_len: usize, max: usize },
26    /// Helpers do not emit an empty data pkt-line (`0004`).
27    ///
28    /// gitprotocol-common: implementations SHOULD NOT send `"0004"`.
29    /// Parsers still accept it as an empty data payload.
30    #[error("refusing to encode empty data pkt-line 0004")]
31    EmptyDataPkt,
32    /// Text helper received a payload that is not UTF-8.
33    #[error("text pkt-line payload is not valid UTF-8")]
34    TextUtf8,
35    /// v1 capability trailer after NUL is not UTF-8.
36    #[error("v1 capability trailer is not valid UTF-8")]
37    CapabilityUtf8,
38    /// v2 capability advertisement did not start with `version 2`.
39    #[error("v2 capability advertisement missing protocol version")]
40    MissingProtocolVersion,
41    /// v2 capability advertisement did not end with flush-pkt.
42    #[error("v2 capability advertisement missing flush-pkt")]
43    MissingFlush,
44    /// delim-pkt or response-end-pkt appeared inside a v2 capability advertisement.
45    ///
46    /// gitprotocol-v2 `capability-advertisement` is version, capability lines, then flush-pkt.
47    #[error("unexpected special pkt-line in v2 capability advertisement")]
48    UnexpectedSpecial,
49}