Skip to main content

rex_app/ui_helper/
outputs.rs

1use std::fmt;
2use thiserror::Error;
3
4pub enum Output {
5    Nothing(Field),
6    Accepted(Field),
7}
8
9impl fmt::Display for Output {
10    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
11        match self {
12            Output::Nothing(value) => write!(f, "{value}: Nothing to check"),
13            Output::Accepted(value) => write!(f, "{value}: Accepted"),
14        }
15    }
16}
17
18#[derive(PartialEq, Debug, Error)]
19pub enum Field {
20    #[error("Date")]
21    Date,
22    #[error("Tx Method")]
23    TxMethod,
24    #[error("Amount")]
25    Amount,
26    #[error("Tx Type")]
27    TxType,
28    #[error("Tags")]
29    Tags,
30}
31
32#[derive(Debug, Error)]
33pub enum VerifierError {
34    #[error("Date: Unknown date")]
35    InvalidDate,
36    #[error("Date: Year length not acceptable. Example Date: 2022-05-01")]
37    InvalidYear,
38    #[error("Date: Month length not acceptable. Example Date: 2022-05-01")]
39    InvalidMonth,
40    #[error("Date: Day length not acceptable. Example Date: 2022-05-01")]
41    InvalidDay,
42    #[error("Date: Month must be between 01-12")]
43    MonthTooBig,
44    #[error("Date: Day must be between 01-31")]
45    DayTooBig,
46    #[error("Date: Date not acceptable and possibly non-existing")]
47    NonExistingDate,
48    #[error("Amount: Value must be bigger than zero")]
49    AmountBelowZero,
50    #[error("TX Method: Transaction Method not found")]
51    InvalidTxMethod,
52    #[error(
53        "TX Type: Transaction Type not acceptable. Values: Expense/Income/Transfer/Borrow/Borrow Repay/Lend/Lend Repay/I/E/T/B/BR/L/LR"
54    )]
55    InvalidTxType,
56    #[error("{0}: Error acquired while validating input")]
57    ParsingError(Field),
58    #[error("Amount: TX Method cannot be empty. Value of B cannot be determined")]
59    InvalidBValue,
60    #[error("Tags: Non-existing tags cannot be accepted")]
61    NonExistingTag,
62    #[error("Others: Something went wrong while verifying input. Error: {0}")]
63    Others(String),
64}
65
66#[derive(Debug, Error)]
67pub enum SteppingError {
68    #[error("Date: Failed to step due to invalid date format")]
69    InvalidDate,
70    #[error("Tx Method: Failed to step as the tx method does not exists")]
71    InvalidTxMethod,
72    #[error("Amount: Failed to step due to invalid amount format")]
73    InvalidAmount,
74    #[error("Tx Type: Failed to step due to invalid tx type")]
75    InvalidTxType,
76    #[error("Tags: Failed to step as the tag does not exists")]
77    InvalidTags,
78    #[error("Amount: Failed to step value. Value of B cannot be determined")]
79    UnknownBValue,
80    #[error("{0}: Error acquired while validating input")]
81    ParsingError(Field),
82}