1use feldera_types::config::StorageBackendConfig;
2use object_store::Error as ObjectStoreError;
3use serde::ser::SerializeStruct;
4use serde::{Serialize, Serializer};
5use std::io::ErrorKind;
6use std::path::PathBuf;
7use thiserror::Error;
8use uuid::Uuid;
9
10#[derive(Clone, Error, Debug)]
12pub enum StorageError {
13 #[error("{0}")]
15 StdIo(ErrorKind),
16
17 #[error("A process with PID {0} is already using the storage directory {1:?}.")]
22 StorageLocked(u32, PathBuf),
23
24 #[error("Couldn't find the specified checkpoint ({0:?}).")]
26 CheckpointNotFound(Uuid),
27
28 #[error("Cannot perform operation because storage is not enabled.")]
30 StorageDisabled,
31 #[error("Failed to serialize/deserialize bloom filter.")]
33 BloomFilter,
34
35 #[error("Path is not UTF-8: {}", .0.display())]
37 InvalidPath(PathBuf),
38
39 #[error("Unable to parse URL {0:?}")]
41 InvalidURL(String),
42
43 #[error("Error accessing object store: {0}")]
45 ObjectStore(String),
46
47 #[error("The requested storage backend ({0:?}) is not available in the open-source version of feldera"
49 )]
50 BackendNotSupported(StorageBackendConfig),
51}
52
53impl From<std::io::Error> for StorageError {
54 fn from(value: std::io::Error) -> Self {
55 Self::StdIo(value.kind())
56 }
57}
58
59impl From<ObjectStoreError> for StorageError {
60 fn from(value: ObjectStoreError) -> Self {
61 Self::ObjectStore(value.to_string())
62 }
63}
64
65impl Serialize for StorageError {
66 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
67 where
68 S: Serializer,
69 {
70 match self {
71 Self::StdIo(error) => {
72 let mut ser = serializer.serialize_struct("IOError", 1)?;
73 ser.serialize_field("kind", &error.to_string())?;
74 ser.end()
75 }
76 error => error.serialize(serializer),
77 }
78 }
79}