timelog/
error.rs

1//! An error that occurs in working with timelogs
2use thiserror;
3
4use crate::date;
5
6/// Errors encountered accessing files and directories.
7#[derive(Eq, thiserror::Error, Debug, PartialEq)]
8pub enum PathError {
9    /// Error accessing a file when reading. File is first string, error message is second.
10    #[error("Error accessing file '{0}': {1}")]
11    FileAccess(String, String),
12
13    /// Error writing to a file. File is first string, error message is second.
14    #[error("Error writing to file '{0}': {1}")]
15    FileWrite(String, String),
16
17    /// Required filename not supplied.
18    #[error("Required filename not supplied")]
19    FilenameMissing,
20
21    /// Attempt to access a file in directory that is not available. Directory is first string,
22    /// error message is second.
23    #[error("Missing directory '{0}': {1}")]
24    InvalidPath(String, String),
25
26    /// Invalid path for the logfiles.
27    #[error("Logfiles path contains invalid characters")]
28    InvalidTimelogPath,
29
30    /// Invalid path for the stack file.
31    #[error("Stack file path contains invalid characters")]
32    InvalidStackPath,
33
34    /// Invalid path for the logfiles.
35    #[error("Config path contains invalid characters")]
36    InvalidConfigPath,
37
38    /// The filename references an existing file.
39    #[error("Cannot overwrite, '{0}' already exists")]
40    AlreadyExists(String),
41
42    /// The filename references an existing file. File is first string, error message is second.
43    #[error("Cannot rename '{0}': {1}")]
44    RenameFailure(String, String),
45
46    /// Cannot create path. Path is first string, error message is second.
47    #[error("Cannot create path '{0}': {1}")]
48    CantCreatePath(String, String),
49
50    /// Cannot read timelog
51    #[error("Cannot read timelog")]
52    CantReadTimelog,
53
54    /// Cannot write to report file
55    #[error("Cannot write report file")]
56    CantWriteReport
57}
58
59/// Enumeration of errors that can happen processing timelogs
60#[derive(thiserror::Error, Debug, PartialEq, Eq)]
61pub enum Error {
62    /// Not a validly formatted entry line.
63    #[error(transparent)]
64    InvalidEntryLine {
65        #[from]
66        source: crate::entry::EntryError
67    },
68
69    /// Entry line is missing the required stamp.
70    #[error("Missing required stamp.")]
71    MissingDate,
72
73    /// Invalid starting date in a date pair.
74    #[error("Invalid starting date.")]
75    StartDateFormat,
76
77    /// Invalid ending date in a date pair.
78    #[error("Invalid ending date.")]
79    EndDateFormat,
80
81    /// Unable to pop stack item.
82    #[error("Unable to pop stack item")]
83    StackPop,
84
85    /// Invalid drop argument
86    #[error("Invalid drop argument '{0}'")]
87    InvalidDrop(String),
88
89    /// Invalid drop argument
90    #[error("Invalid pos integer argument '{0}'")]
91    InvalidInt(String),
92
93    /// Project descriptors invalid
94    #[error("Bad project filters")]
95    BadProjectFilter,
96
97    /// Not a valid timelog command
98    #[error("'{0}' is not a valid command")]
99    InvalidCommand(String),
100
101    /// Deprecated command
102    #[error("Deprecated! Use '{0}' instead.")]
103    DeprecatedCommand(&'static str),
104
105    /// Failed to execute editor on logfile. File is first string, error message is second.
106    #[error("Editor '{0}' failed to execute: {1}")]
107    EditorFailed(String, String),
108
109    /// Unexpected argument
110    #[error("Argument '{0}' is unexpected")]
111    UnexpectedArgument(String),
112
113    /// Invalid argument for 'was'
114    #[error("Argument '{0}' should have been a time")]
115    InvalidWasArgument(String),
116
117    /// Tried to change stop entry
118    #[error("Cannot edit stop entry")]
119    InvalidStopEdit,
120
121    /// Tried to change ignore entry
122    #[error("Cannot edit ignore entry")]
123    InvalidIgnoreEdit,
124
125    /// Errors in path/file handling
126    #[error(transparent)]
127    DateError {
128        #[from]
129        source: date::DateError
130    },
131
132    /// Errors in path/file handling
133    #[error(transparent)]
134    PathError {
135        #[from]
136        source: PathError
137    }
138}
139
140impl From<xml::writer::Error> for Error {
141    /// Conversion from an [`xml::writer::Error`] to a timelog [`enum@Error`].
142    fn from(_e: xml::writer::Error) -> Error { PathError::CantWriteReport.into() }
143}