tdo_core/error.rs
1//! Custom Error Types for errors that may occur when handling todos (or lists).
2
3/// Custom Result Type for tdo.
4///
5/// This abbreviation is introduced since many functions throughout the crate return
6/// this type of result, which bundles all possible errors of the `tdo_core` crate.
7pub type TdoResult<T> = Result<T>;
8
9
10/// Errors that can arise when working with todo lists.
11pub mod todo_error {
12 error_chain! {
13 errors {
14 /// The requested item is not in the list.
15 NotInList {
16 description("Todo is not in this list")
17 }
18 /// The requested todo list does not exist.
19 NoSuchList {
20 description("No such list")
21 }
22 /// The default list is tried to be removed.
23 CanNotRemoveDefault {
24 description("The default list can no be removed")
25 }
26 /// A list with the same name already exists.
27 NameAlreadyExists {
28 description("There already exists a list with this name")
29 }
30 /// A todo with the same ID already exists.
31 IDAlreadyExists {
32 description("There already exists a todo with this ID")
33 }
34 }
35 }
36}
37
38/// Errors that can arise when interacting with github.
39pub mod github_error {
40 error_chain! {
41 errors {
42 /// Repository does not exist
43 DoesNotExist {
44 description("Repository does not exist or you have no access to it")
45 }
46 /// Bad credentials
47 BadCredentials {
48 description("Bad credentials")
49 }
50 /// Not allowed to move error
51 NotAllowedToMove {
52 description("A github issue is not allowed to be moved out ouf the default list")
53 }
54 /// Not a guthub issue eroor
55 NoIssueAsigned {
56 description("There is no github issue asigned to this todo")
57 }
58 /// Unknown error
59 UnknownError {
60 description("An unknown error occured")
61 }
62 }
63 }
64}
65
66/// The Errors that may occur while interacting with the file system.
67pub mod storage_error {
68 error_chain! {
69 errors {
70 /// The accessed file is corrupted. This is most likely
71 /// because someone edited the JSON file manually.
72 FileCorrupted {
73 description("File is corrupted")
74 }
75 /// The data could not be written to the file.
76 SaveFailure {
77 description("File could not be saved")
78 }
79 /// The requested file could not be found.
80 FileNotFound {
81 description("File was not found")
82 }
83 /// The conversion of an older format failed.
84 UnableToConvert {
85 description("File could not be converted automatically")
86 }
87 }
88 }
89}
90
91error_chain! {
92 links {
93 TodoError(todo_error::Error, todo_error::ErrorKind) #[doc = "An error within the tdo data structures occured."];
94 StorageError(storage_error::Error, storage_error::ErrorKind) #[doc = "A storage-related error occured while interacting with the file system."];
95 GithubError(github_error::Error, github_error::ErrorKind) #[doc = "A github communication-related error occured."];
96 }
97}