bible_lib/
error.rs

1use std::fmt::{Display, Formatter};
2
3
4/// Errors that can occur in the Bible Lib
5#[derive(Debug)]
6pub enum BibleLibError {
7    /// The specified custom translation file is invalid or does not exist.
8    InvalidCustomTranslationFile,
9    /// The specified verse was not found in the translation.
10    VerseNotFound,
11    /// The specified chapter was not found in the translation.
12    ChapterNotFound,
13    /// The specified book was not found in the translation.
14    BookNotFound,
15    /// The verse format provided is invalid.
16    InvalidVerseFormat,
17    /// An I/O error occurred.
18    IOError(std::io::Error),
19}
20
21impl Display for BibleLibError {
22    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
23        match self {
24            BibleLibError::InvalidCustomTranslationFile => {
25                write!(f, "The specified custom translation file is invalid or does not exist.")
26            }
27            BibleLibError::VerseNotFound => {
28                write!(f, "The specified verse was not found in the translation.")
29            }
30            BibleLibError::ChapterNotFound => {
31                write!(f, "The specified chapter was not found in the translation.")
32            }
33            BibleLibError::BookNotFound => {
34                write!(f, "The specified book was not found in the translation.")
35            }
36            BibleLibError::InvalidVerseFormat => {
37                write!(f, "The verse format provided is invalid.")
38            }
39            BibleLibError::IOError(e) => {
40                write!(f, "An I/O error occurred: {}", e)
41            }
42        }
43    }
44}