1use std::{error::Error, fmt::Display};
2
3#[derive(Debug)]
4pub enum SaveError {
5 Format,
6 File,
7 Write,
8}
9
10impl Error for SaveError {}
11
12impl Display for SaveError {
13 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14 match self {
15 Self::Format => write!(f, "Unable to format data"),
16 Self::Write => write!(f, "Unable to write to the desired path"),
17 Self::File => write!(f, "Unable to create the file or parent directories"),
18 }
19 }
20}
21
22#[derive(Debug)]
23pub enum ConversionError {
24 PasswordGeneration,
25 NoEntry,
26 Exists,
27 PromptError,
28}
29
30impl Error for ConversionError {}
31
32impl Display for ConversionError {
33 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34 match self {
35 Self::PasswordGeneration => {
36 write!(f, "Constraints for password generation could not be met")
37 }
38 Self::NoEntry => write!(f, "No relevant entry found in schema"),
39 Self::Exists => write!(f, "Entry already exists"),
40 Self::PromptError => write!(f, "Error during prompting"),
41 }
42 }
43}
44
45#[derive(Debug)]
46pub enum EncryptionError {
47 Encryption,
48}
49
50impl Error for EncryptionError {}
51
52impl Display for EncryptionError {
53 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
54 match self {
55 EncryptionError::Encryption => write!(f, "Failed to encrypt data"),
56 }
57 }
58}
59
60#[derive(Debug)]
61pub enum DecryptionError {
62 Decryption,
63}
64
65impl Error for DecryptionError {}
66
67impl Display for DecryptionError {
68 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
69 match self {
70 DecryptionError::Decryption => write!(f, "Failed to decrypt data"),
71 }
72 }
73}
74
75#[derive(Debug)]
76pub enum InteractionError {
77 DifferentPasswords,
78}
79
80impl Error for InteractionError {}
81
82impl Display for InteractionError {
83 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
84 match self {
85 Self::DifferentPasswords => write!(f, "Given passwords don't match"),
86 }
87 }
88}
89
90#[derive(Debug)]
91pub enum SchemaError {
92 BadType,
93 BadValues,
94}
95
96impl Error for SchemaError {}
100
101impl Display for SchemaError {
102 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
103 match self {
104 Self::BadType => write!(f, "Not a valid schema type"),
105 Self::BadValues => write!(f, "Invalid values for creating data to store"),
106 }
107 }
108}