ical/tree/error.rs
1//! # Errors
2//!
3//! The parsing errors.
4//!
5//! [`IcalParseError`] is the single error type returned by `IcalCst::parse` and
6//! the line tokeniser it drives, each variant pinpointing one structural failure
7//! and carrying the offending text. Parsing is the only fallible bridge in the
8//! crate: decoding, encoding and serializing never fail, so this is the whole
9//! error surface.
10
11use core::{error, fmt};
12
13use alloc::string::String;
14
15/// An error raised while parsing iCalendar text.
16#[derive(Clone, Debug, Eq, PartialEq)]
17pub enum IcalParseError {
18 /// A line carried no CR?LF separator.
19 MissingCrlf(String),
20 /// A content line carried no colon separating the name from the value.
21 MissingPropertyColon(String),
22 /// A content line's name or parameters were not valid UTF-8; only a value
23 /// may carry a foreign charset.
24 NonUtf8Header(String),
25 /// A calendar did not open with a BEGIN:VCALENDAR line.
26 ExpectedBegin(String),
27 /// A calendar was left open by a missing END:VCALENDAR line.
28 MissingEnd(String),
29}
30
31impl fmt::Display for IcalParseError {
32 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33 match self {
34 Self::MissingCrlf(data) => {
35 write!(f, "Content is missing a line separator: {data}")
36 }
37 Self::MissingPropertyColon(data) => {
38 write!(f, "Content line is missing a value separator: {data}")
39 }
40 Self::NonUtf8Header(data) => {
41 write!(
42 f,
43 "Content line name or parameters are not valid UTF-8: {data}"
44 )
45 }
46 Self::ExpectedBegin(data) => {
47 write!(f, "Card does not open with a BEGIN line: {data}")
48 }
49 Self::MissingEnd(data) => {
50 write!(f, "Card is left open by a missing END line: {data}")
51 }
52 }
53 }
54}
55
56impl error::Error for IcalParseError {}