aboutsummaryrefslogtreecommitdiff
path: root/src/error/mod.rs
blob: 9ac6816918cacfaa7f0554be1e24bcd966ae6719 (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
/* Copyright (C) 2019  Akshay Oppiliappan <[email protected]>
 * Refer to LICENCE for more information.
 * */

#[derive(Debug)]
pub enum CalcError {
    Math(Math),
    Syntax(String),
    Parser(String),
}

#[derive(Debug)]
pub enum Math {
    DivideByZero,
    OutOfBounds,
    UnknownBase
}

pub fn handler(e: CalcError) -> String {
    match e {
        CalcError::Math(math_err) => {
            match math_err {
                Math::DivideByZero => format!("Math Error: Divide by zero error!"),
                Math::OutOfBounds => format!("Domain Error: Out of bounds!"),
                Math::UnknownBase => format!("Base too large! Accepted ranges: 0 - 36")
            }
        },
        CalcError::Syntax(details) => {
            format!("Syntax Error: {}", details)
        },
        CalcError::Parser(details) => {
            format!("Parser Error: {}", details)
        }
    }
}