aboutsummaryrefslogtreecommitdiff
path: root/src/error.rs
blob: 471af3aa0d73b8b861ea28edc5d841c494227927 (plain)
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
use crate::{cli::CliError, lisp::error::LispError};

use std::{error, fmt, io};

use sdl2::ttf;

#[derive(Debug)]
pub enum AppError {
    Lisp(LispError),
    File(io::Error),
    Sdl(String),
    SdlTTF(SdlTTFError),
    Cli(CliError),
}

impl fmt::Display for AppError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Lisp(e) => write!(f, "lisp error: {}", e),
            Self::File(e) => write!(f, "file error: {}", e),
            Self::Sdl(e) => write!(f, "sdl2 error: {}", e),
            Self::SdlTTF(e) => write!(f, "ttf error: {}", e),
            Self::Cli(e) => write!(f, "cli error: {}", e),
        }
    }
}

#[derive(Debug)]
pub enum SdlTTFError {
    Font(ttf::FontError),
    Init(ttf::InitError),
}

impl fmt::Display for SdlTTFError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Font(e) => write!(f, "font error: {}", e),
            Self::Init(e) => write!(f, "init error: {}", e),
        }
    }
}

impl error::Error for AppError {}
impl error::Error for SdlTTFError {}