1use std::error::Error;
2use std::fmt;
3
4#[derive(Debug, PartialEq)]
5pub enum FormatError {
6 InvalidEscapeCharacter(usize, char),
7 UnclosedPlaceholder,
8 UnopenedPlaceholder,
9 InvalidIndex(String),
10 InvalidPadding(String),
11 EmptyFormatter,
12}
13
14impl fmt::Display for FormatError {
15 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16 match self {
17 FormatError::InvalidEscapeCharacter(pos, ch) => write!(
18 f,
19 "[output-format] invalid escape character of '{}' at '{}'",
20 ch, pos
21 ),
22 FormatError::UnclosedPlaceholder => write!(
23 f,
24 "[output-format] all opened placeholders must be closed by '}}'"
25 ),
26 FormatError::UnopenedPlaceholder => write!(
27 f,
28 "[output-format] an unopened placeholder could not be closed by '}}'"
29 ),
30 FormatError::InvalidIndex(index) => {
31 write!(f, "[output-format] unable to parse index of '{}'", index)
32 }
33 FormatError::InvalidPadding(padding) => write!(
34 f,
35 "[output-format] unable to parse padding of '{}'",
36 padding
37 ),
38 FormatError::EmptyFormatter => {
39 write!(f, "[output-format] output formatter must be set")
40 }
41 }
42 }
43}
44
45impl Error for FormatError {}