aboutsummaryrefslogtreecommitdiff
path: root/apps/cassiopeia/src/error.rs
diff options
context:
space:
mode:
authorMx Kookie <kookie@spacekookie.de>2020-12-19 15:15:20 +0000
committerMx Kookie <kookie@spacekookie.de>2020-12-21 05:19:49 +0100
commit69eaad1c9f934bccaf7e28529a6b1657345f0184 (patch)
tree4e7517a16f7303f5f6efbd02e4aae85bdc5aec29 /apps/cassiopeia/src/error.rs
parentb9c988f42504c2e4cfa0715ac8f2d2a0db591cad (diff)
cassiopeia: changing internal data representation to timeline module
What this allows us to do is much better relationship tracking between sessions and invoices. The CASS file already has all the structure we need, and it would be silly to replicate it via complicated time association algorithms. This approach uses the linear nature of the data file to track the position relative to other entries. The timeline module is then responsible for making changes to the internal representation (in case it is being used as a library for multi-query commands), and emitting a `Delta` type that can be used to easily patch the IR in question, because the mapping between the timeline and IR representations is linear.
Diffstat (limited to 'apps/cassiopeia/src/error.rs')
-rw-r--r--apps/cassiopeia/src/error.rs72
1 files changed, 72 insertions, 0 deletions
diff --git a/apps/cassiopeia/src/error.rs b/apps/cassiopeia/src/error.rs
new file mode 100644
index 000000000000..31f5414c4f86
--- /dev/null
+++ b/apps/cassiopeia/src/error.rs
@@ -0,0 +1,72 @@
+//! A set of error types for cassiopeia
+
+use std::error::Error;
+use std::fmt::{self, Display, Formatter};
+
+/// User errors that can occur when using cassiopeia
+///
+/// None of these errors are the fault of the program, but rather
+/// fault of the user for giving invalid commands. They must never
+/// make the program crash, but instead need to print human friendly
+/// error messages.
+#[derive(Debug)]
+pub enum UserError {
+ /// Trying to start a session when one exists
+ ActiveSessionExists,
+ /// Trying to stop a session when none exists
+ NoActiveSession,
+ /// Trying to create a second invoice on the same day
+ SameDayInvoice,
+ /// No work was done since the last invoice
+ NoWorkInvoice,
+}
+
+impl Display for UserError {
+ fn fmt(&self, f: &mut Formatter) -> fmt::Result {
+ write!(f, "You're doing it wrong!")
+ }
+}
+
+impl Error for UserError {}
+
+pub type UserResult<T> = Result<T, UserError>;
+
+/// Errors that occur when parsing a file
+///
+/// These errors can pre-maturely terminate the run of the program,
+/// but must print a detailed error about what is wrong. Also,
+/// because they are technically a superset of
+/// [`UserError`](self::UserError), one of the variants is an embedded
+/// user error.
+#[derive(Debug)]
+pub enum ParseError {
+ /// An embedded user error
+ ///
+ /// This error means that the structure of the parsed file is
+ /// wrong, with an invalid sequence of events expressed
+ User(UserError),
+ /// An invalid keyword was found
+ BadKeyword { line: usize, tokn: String },
+ /// A bad timestamp was found
+ BadTimestamp { line: usize, tokn: String },
+ /// A bad date was found
+ BadDate { line: usize, tokn: String },
+ /// An unknown parse error occured
+ Unknown,
+}
+
+impl Display for ParseError {
+ fn fmt(&self, f: &mut Formatter) -> fmt::Result {
+ write!(f, "The parsed file was bad :(")
+ }
+}
+
+impl Error for ParseError {}
+
+pub type ParseResult<T> = Result<T, ParseError>;
+
+impl From<UserError> for ParseError {
+ fn from(user: UserError) -> Self {
+ ParseError::User(user)
+ }
+}