1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#[derive(Debug)]
pub enum Error {
LibusbError(libusb::Error),
CP437Error(String),
ImageError(image::ImageError),
NoBulkEndpoint,
NoReplacementFound(String),
NoPrintData,
PrinterError(String),
WrongMarkdown,
NoTables,
NoTableFound(String),
NoWidth,
NoQrContent(String),
NoQrContents,
Encoding
}
impl std::fmt::Display for Error {
fn fmt(&self, formatter: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
let content = match self {
Error::LibusbError(e) => format!("Libusb error: {}", e),
Error::CP437Error(detail) => format!("CP437 error: {}", detail),
Error::ImageError(e) => format!("Image error: {}", e),
Error::NoBulkEndpoint => format!("No bulk endpoint could be found"),
Error::NoReplacementFound(replacement) => format!("Could not find replacement for tag {{{}}}", replacement),
Error::NoPrintData => format!("Print data must be supplied for this instruction"),
Error::PrinterError(detail) => format!("An error occured while printing, {}", detail),
Error::WrongMarkdown => format!("Incorrect markdown structure"),
Error::NoTables => format!("Not a single table was found in the PrintData structure"),
Error::NoTableFound(table) => format!("No table was found for id {{{}}}", table),
Error::NoWidth => format!("No width was found for the selected font"),
Error::NoQrContent(name) => format!("Could not find qr code content for \"{}\"", name),
Error::NoQrContents => format!("Could not find qr contents"),
Error::Encoding => format!("An unsupported utf-8 character was found when passing to cp437")
};
write!(formatter, "{}", content)
}
}
impl std::error::Error for Error{}