about summary refs log tree commit diff
path: root/src/database/mod.rs
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2021-08-04 13:28:24 +0300
committerVika <vika@fireburn.ru>2021-08-04 13:28:24 +0300
commitbfef058f199d195bb2c16d791c3f1bfeccb5614e (patch)
tree3b8a6ffac36b81be4df53943659a56c2a883713a /src/database/mod.rs
parent1589475ebefa72c2981d1b50611531545c1dd32a (diff)
Fixed a VERY WRONG way to handle stream errors
for future reference: stream operations returning Result satisfy
conditions for the futures::stream::TryStreamExt trait, allowing you to
use `TryStreamExt::try_collect::<T>()` and receive a Result<T>.
Diffstat (limited to 'src/database/mod.rs')
-rw-r--r--src/database/mod.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/database/mod.rs b/src/database/mod.rs
index 27c0025..7b144f8 100644
--- a/src/database/mod.rs
+++ b/src/database/mod.rs
@@ -90,12 +90,20 @@ impl serde::Serialize for StorageError {
 impl StorageError {
     /// Create a new StorageError of an ErrorKind with a message.
     fn new(kind: ErrorKind, msg: &str) -> Self {
-        StorageError {
+        Self {
             msg: msg.to_string(),
             source: None,
             kind,
         }
     }
+    /// Create a StorageError using another arbitrary Error as a source.
+    fn with_source(kind: ErrorKind, msg: &str, source: Box<dyn std::error::Error>) -> Self {
+        Self {
+            msg: msg.to_string(),
+            source: Some(source),
+            kind
+        }
+    }
     /// Get the kind of an error.
     pub fn kind(&self) -> ErrorKind {
         self.kind