1use thiserror;
3
4use crate::date;
5
6#[derive(Eq, thiserror::Error, Debug, PartialEq)]
8pub enum PathError {
9 #[error("Error accessing file '{0}': {1}")]
11 FileAccess(String, String),
12
13 #[error("Error writing to file '{0}': {1}")]
15 FileWrite(String, String),
16
17 #[error("Required filename not supplied")]
19 FilenameMissing,
20
21 #[error("Missing directory '{0}': {1}")]
24 InvalidPath(String, String),
25
26 #[error("Logfiles path contains invalid characters")]
28 InvalidTimelogPath,
29
30 #[error("Stack file path contains invalid characters")]
32 InvalidStackPath,
33
34 #[error("Config path contains invalid characters")]
36 InvalidConfigPath,
37
38 #[error("Cannot overwrite, '{0}' already exists")]
40 AlreadyExists(String),
41
42 #[error("Cannot rename '{0}': {1}")]
44 RenameFailure(String, String),
45
46 #[error("Cannot create path '{0}': {1}")]
48 CantCreatePath(String, String),
49
50 #[error("Cannot read timelog")]
52 CantReadTimelog,
53
54 #[error("Cannot write report file")]
56 CantWriteReport
57}
58
59#[derive(thiserror::Error, Debug, PartialEq, Eq)]
61pub enum Error {
62 #[error(transparent)]
64 InvalidEntryLine {
65 #[from]
66 source: crate::entry::EntryError
67 },
68
69 #[error("Missing required stamp.")]
71 MissingDate,
72
73 #[error("Invalid starting date.")]
75 StartDateFormat,
76
77 #[error("Invalid ending date.")]
79 EndDateFormat,
80
81 #[error("Unable to pop stack item")]
83 StackPop,
84
85 #[error("Invalid drop argument '{0}'")]
87 InvalidDrop(String),
88
89 #[error("Invalid pos integer argument '{0}'")]
91 InvalidInt(String),
92
93 #[error("Bad project filters")]
95 BadProjectFilter,
96
97 #[error("'{0}' is not a valid command")]
99 InvalidCommand(String),
100
101 #[error("Deprecated! Use '{0}' instead.")]
103 DeprecatedCommand(&'static str),
104
105 #[error("Editor '{0}' failed to execute: {1}")]
107 EditorFailed(String, String),
108
109 #[error("Argument '{0}' is unexpected")]
111 UnexpectedArgument(String),
112
113 #[error("Argument '{0}' should have been a time")]
115 InvalidWasArgument(String),
116
117 #[error("Cannot edit stop entry")]
119 InvalidStopEdit,
120
121 #[error("Cannot edit ignore entry")]
123 InvalidIgnoreEdit,
124
125 #[error(transparent)]
127 DateError {
128 #[from]
129 source: date::DateError
130 },
131
132 #[error(transparent)]
134 PathError {
135 #[from]
136 source: PathError
137 }
138}
139
140impl From<xml::writer::Error> for Error {
141 fn from(_e: xml::writer::Error) -> Error { PathError::CantWriteReport.into() }
143}