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 TableConnectError {
35 fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
36 match self {
37 TableConnectError::Permissions(why) => write!(
38 fmt,
39 "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"
40 ),
41 TableConnectError::NotAFile(path) => {
42 write!(
43 fmt,
44 "Specified path `{}` is not a valid SQLite database file!",
45 path.to_string_lossy()
46 )
47 }
48 TableConnectError::DoesNotExist(path) => {
49 write!(
50 fmt,
51 "Database file `{}` does not exist at the specified path!",
52 path.to_string_lossy()
53 )
54 }
55 TableConnectError::NotBackupRoot => write!(
56 fmt,
57 "The path provided points to a database inside of an iOS backup, not the root of the backup."
58 ),
59 }
60 }
61}
62
63impl Display for TableError {
64 fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
65 match self {
66 TableError::CannotConnect(why) => write!(fmt, "{why}"),
67 TableError::CannotRead(why) => write!(fmt, "Cannot read from filesystem: {why}"),
68 TableError::QueryError(error) => write!(fmt, "Failed to query table: {error}"),
69 }
70 }
71}
72
73impl std::error::Error for TableError {
74 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
75 match self {
76 TableError::QueryError(e) => Some(e),
77 TableError::CannotConnect(e) => Some(e),
78 TableError::CannotRead(e) => Some(e),
79 }
80 }
81}
82
83impl std::error::Error for TableConnectError {
84 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
85 match self {
86 TableConnectError::Permissions(e) => Some(e),
87 _ => None,
88 }
89 }
90}
91
92impl From<std::io::Error> for TableError {
93 fn from(err: std::io::Error) -> Self {
94 TableError::CannotRead(err)
95 }
96}
97
98impl From<rusqlite::Error> for TableError {
99 fn from(err: rusqlite::Error) -> Self {
100 TableError::QueryError(err)
101 }
102}