aboutsummaryrefslogtreecommitdiff
path: root/lockchain-core/src/errors
diff options
context:
space:
mode:
authorKatharina Fey <kookie@spacekookie.de>2018-07-09 10:43:38 +0200
committerKatharina Fey <kookie@spacekookie.de>2018-07-09 10:43:38 +0200
commit99ccbd7ddc1917dc2c984b046e250bf74e0aa2d3 (patch)
tree6249a2f13c8b7bec195d20a0cf1b4cc264b2f64e /lockchain-core/src/errors
parent7bf79304628e5e95b20690f1a12cd9e5aec107bf (diff)
Refactoring the error modules to now contain sub-error types
This isn't ideal yet but good enough for now. Errors can be added via a new variant in lockchain::errors::Error easily
Diffstat (limited to 'lockchain-core/src/errors')
-rw-r--r--lockchain-core/src/errors/auth.rs29
-rw-r--r--lockchain-core/src/errors/crypto.rs28
-rw-r--r--lockchain-core/src/errors/data.rs23
-rw-r--r--lockchain-core/src/errors/mod.rs55
-rw-r--r--lockchain-core/src/errors/vault.rs58
5 files changed, 193 insertions, 0 deletions
diff --git a/lockchain-core/src/errors/auth.rs b/lockchain-core/src/errors/auth.rs
new file mode 100644
index 0000000..32ce33a
--- /dev/null
+++ b/lockchain-core/src/errors/auth.rs
@@ -0,0 +1,29 @@
+//! Athentication errors
+
+use std::error::Error as StdError;
+use std::fmt::{Display, Formatter, Result};
+
+/// Common errors that can occur when authenticating users
+#[derive(Debug, Serialize, Deserialize)]
+pub enum Error {
+ /// Forking an authentication task failed
+ FailedFork,
+ /// Failed to authenticate via PAM due to a PAM related issue
+ FailedPAM,
+ /// The provided user either doesn't exist or is not authorised
+ UserNotAuthorised,
+}
+
+impl StdError for Error {}
+
+impl Display for Error {
+ fn fmt(&self, f: &mut Formatter) -> Result {
+ write!(
+ f,
+ "{}",
+ match self {
+ _ => "Unknown failure",
+ }
+ )
+ }
+}
diff --git a/lockchain-core/src/errors/crypto.rs b/lockchain-core/src/errors/crypto.rs
new file mode 100644
index 0000000..a0c12a2
--- /dev/null
+++ b/lockchain-core/src/errors/crypto.rs
@@ -0,0 +1,28 @@
+//! I sell crypto and crypto accessories (errors)
+
+use std::error::Error as StdError;
+use std::fmt::{Display, Formatter, Result};
+
+#[derive(Debug, Serialize, Deserialize)]
+pub enum Error {
+ /// Provided crypto layer is lacking features or missing
+ InvalidCryptoLayer,
+ /// Failed to initialise cryptography module
+ FailedCrypto,
+ /// Invalid key or user identity
+ FailedKey,
+}
+
+impl StdError for Error {}
+
+impl Display for Error {
+ fn fmt(&self, f: &mut Formatter) -> Result {
+ write!(
+ f,
+ "{}",
+ match self {
+ _ => "Unknown failure",
+ }
+ )
+ }
+}
diff --git a/lockchain-core/src/errors/data.rs b/lockchain-core/src/errors/data.rs
new file mode 100644
index 0000000..b854d37
--- /dev/null
+++ b/lockchain-core/src/errors/data.rs
@@ -0,0 +1,23 @@
+//! Data integrity errors
+
+use std::error::Error as StdError;
+use std::fmt::{Display, Formatter, Result};
+
+#[derive(Debug, Serialize, Deserialize)]
+pub enum Error {
+
+}
+
+impl StdError for Error {}
+
+impl Display for Error {
+ fn fmt(&self, f: &mut Formatter) -> Result {
+ write!(
+ f,
+ "{}",
+ match self {
+ _ => "Unknown failure",
+ }
+ )
+ }
+}
diff --git a/lockchain-core/src/errors/mod.rs b/lockchain-core/src/errors/mod.rs
new file mode 100644
index 0000000..d6347a1
--- /dev/null
+++ b/lockchain-core/src/errors/mod.rs
@@ -0,0 +1,55 @@
+//! Common lockchain error handling
+//!
+//! `Error` is a wrapper type around many different errors
+//! that are provided by different parts of
+//! the `lockchain-core` crate.
+//!
+//! It also re-exports those error types so that a user can use
+//! the error handling module simply by including `lockchain_core::errors::*`
+
+mod auth;
+mod crypto;
+mod data;
+mod vault;
+
+pub use self::auth::Error as AuthError;
+pub use self::crypto::Error as CryptoError;
+pub use self::data::Error as DataError;
+pub use self::vault::Error as VaultError;
+
+use std::error::Error as StdError;
+use std::fmt::{Display, Formatter, Result};
+
+#[derive(Debug, Serialize, Deserialize)]
+pub enum Error {
+ /// A basic vault operation error
+ Vault(VaultError),
+ /// Errors occuring during authentication
+ Auth(AuthError),
+ /// Cryptographic errors
+ Crypto(CryptoError),
+ /// Data integrity or retrieval errors
+ Data(DataError),
+ /// Make sure we don't break user code with new options
+ #[doc(hidden)]
+ __NonExhaustive,
+}
+
+impl StdError for Error {}
+
+impl Display for Error {
+ fn fmt(&self, f: &mut Formatter) -> Result {
+ use self::Error::*;
+ write!(
+ f,
+ "{}",
+ match self {
+ Vault(ee) => format!("VaultError: {}", ee),
+ Auth(ee) => format!("AuthError: {}", ee),
+ Crypto(ee) => format!("CryptoError: {}", ee),
+ Data(ee) => format!("DataError: {}", ee),
+ _ => "Unknown error".into(),
+ }
+ )
+ }
+}
diff --git a/lockchain-core/src/errors/vault.rs b/lockchain-core/src/errors/vault.rs
new file mode 100644
index 0000000..bcfcd13
--- /dev/null
+++ b/lockchain-core/src/errors/vault.rs
@@ -0,0 +1,58 @@
+//! Vault workflow and I/O errors
+
+use std::error::Error as StdError;
+use std::fmt::{Display, Formatter, Result};
+
+#[derive(Debug, Serialize, Deserialize)]
+pub enum Error {
+ /// A vault already exists with that path-id
+ AlreadyExists,
+ /// The provided path is invalid
+ InvalidPath,
+ /// The provided name is invalid
+ ///
+ /// This usually means the backing storage doesn't support some
+ /// character in the name which can sometimes occur if the name
+ /// contains special unicode characters that a filesystem doesn't
+ /// recognise as valid characters.
+ InvalidName,
+ /// The combination of selected components threw a runtime incompatibility error
+ InvalidCompoents {
+ /// Optionally the type that is incompatible (if it can be determined)
+ tt: Option<String>,
+ },
+ /// Vault failed it's checksum self-test
+ ///
+ /// This is problematic because it also means the vault was unable to correct
+ /// any errors. Either the backing storage has some serious issues or maybe
+ /// an external sync process that lockchain can't detect is still working.
+ FailedSelfTest,
+ /// Failed to initialise lockchain vault handler
+ FailedInitalise,
+ /// Failed to create a vault for an unknown reason
+ FailedCreation,
+ /// Failed to load a vault for an unknown reason
+ FailedLoading,
+ /// Failed to close the vault properly.
+ ///
+ /// This could be because the backing storage is no longer available
+ /// or permisions to write have been revoked.
+ FailedClosing,
+ /// Make sure we don't break user code with new options
+ #[doc(hidden)]
+ __NonExhaustive,
+}
+
+impl StdError for Error {}
+
+impl Display for Error {
+ fn fmt(&self, f: &mut Formatter) -> Result {
+ write!(
+ f,
+ "{}",
+ match self {
+ _ => "Unknown failure",
+ }
+ )
+ }
+}