imessage_database/error/
table.rs1use std::{
6 fmt::{Display, Formatter, Result},
7 path::PathBuf,
8};
9
10#[derive(Debug)]
12pub enum TableError {
13 QueryError(rusqlite::Error),
15 CannotConnect(TableConnectError),
17 CannotRead(std::io::Error),
19}
20
21#[derive(Debug)]
23pub enum TableConnectError {
24 Permissions(rusqlite::Error),
26 NotAFile(PathBuf),
28 DoesNotExist(PathBuf),
30 NotBackupRoot,
32}
33
34impl Display for TableError {
35 fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
36 match self {
37 TableError::CannotConnect(why) => match why {
38 TableConnectError::Permissions(why) => write!(
39 fmt,
40 "Unable to read from chat database: {why}\nEnsure full disk access is enabled for your terminal emulator in System Settings > Privacy & Security > Full Disk Access"
41 ),
42 TableConnectError::NotAFile(path) => {
43 write!(
44 fmt,
45 "Specified path `{}` is not a valid SQLite database file!",
46 path.to_string_lossy()
47 )
48 }
49 TableConnectError::DoesNotExist(path) => {
50 write!(
51 fmt,
52 "Database file `{}` does not exist at the specified path!",
53 path.to_string_lossy()
54 )
55 }
56 TableConnectError::NotBackupRoot => write!(
57 fmt,
58 "The path provided points to a database inside of an iOS backup, not the root of the backup."
59 ),
60 },
61 TableError::CannotRead(why) => write!(fmt, "Cannot read from filesystem: {why}"),
62 TableError::QueryError(error) => write!(fmt, "Failed to query table: {error}"),
63 }
64 }
65}
66
67impl From<std::io::Error> for TableError {
68 fn from(err: std::io::Error) -> Self {
69 TableError::CannotRead(err)
70 }
71}
72
73impl From<rusqlite::Error> for TableError {
74 fn from(err: rusqlite::Error) -> Self {
75 TableError::QueryError(err)
76 }
77}