nntp_proxy/protocol/article/
error.rs1use std::fmt;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
7pub enum ParseError {
8 InvalidStatusCode(u16),
10
11 MissingSeparator,
13
14 MissingTerminator,
16
17 InvalidHeader(String),
19
20 UnexpectedBody,
22
23 InvalidYenc(String),
25
26 BufferTooShort,
28
29 InvalidMessageId(String),
31}
32
33impl fmt::Display for ParseError {
34 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
35 match self {
36 Self::InvalidStatusCode(code) => write!(f, "Invalid status code: {}", code),
37 Self::MissingSeparator => {
38 write!(f, "Missing blank line separator between headers and body")
39 }
40 Self::MissingTerminator => write!(f, "Missing multiline terminator (CRLF.CRLF)"),
41 Self::InvalidHeader(msg) => write!(f, "Invalid header: {}", msg),
42 Self::UnexpectedBody => write!(f, "HEAD response should not contain body"),
43 Self::InvalidYenc(msg) => write!(f, "Invalid yenc: {}", msg),
44 Self::BufferTooShort => write!(f, "Buffer too short to contain valid response"),
45 Self::InvalidMessageId(msg) => write!(f, "Invalid message-ID: {}", msg),
46 }
47 }
48}
49
50impl std::error::Error for ParseError {}
51
52impl From<crate::types::validated::ValidationError> for ParseError {
54 fn from(err: crate::types::validated::ValidationError) -> Self {
55 ParseError::InvalidMessageId(err.to_string())
56 }
57}