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
use std::fmt::{Display, Formatter};
use std::io;

use rustyline::error::ReadlineError;
use thiserror::Error;

pub type MyResult<T> = Result<T, MyError>;

#[derive(Error, Debug, PartialEq)]
pub enum EngineError {
    ParseError(String),
    MissingValue,
    MissingUndo,
    MissingRedo,
    MissingClip,
    BadTimeOp,
}

impl Display for EngineError {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        match self {
            EngineError::ParseError(token) => write!(f, "Invalid number or keyword: {}", token),
            EngineError::MissingValue => write!(f, "Not enough values on stack"),
            EngineError::MissingUndo => write!(f, "Start of undo history"),
            EngineError::MissingRedo => write!(f, "End of undo history"),
            EngineError::MissingClip => write!(f, "No value on clipboard"),
            EngineError::BadTimeOp => write!(f, "Unsupported time operation"),
        }
    }
}

#[derive(Error, Debug)]
pub enum MyError {
    #[error(transparent)]
    Clap(#[from] clap::error::Error),
    #[error(transparent)]
    Io(#[from] io::Error),
    #[error(transparent)]
    ParseBigInt(#[from] num::bigint::ParseBigIntError),
    #[error(transparent)]
    ParseBigRatio(#[from] big_rational_str::ParseError),
    #[error(transparent)]
    Readline(#[from] ReadlineError),
    #[error(transparent)]
    Engine(#[from] EngineError),
}