coven_database/
open_error.rs1use crate::DbError;
5use coven_foundation::files::{SettingsError, StoreLockError};
6use coven_foundation::task::{Bug, CarriesBug};
7
8#[derive(Debug, thiserror::Error)]
11pub enum OpenError {
12 #[error(transparent)]
14 Database(#[from] DbError),
15 #[error(transparent)]
17 Migration(#[from] MigrationError),
18 #[error(transparent)]
20 CovenSchema(#[from] CovenSchemaError),
21 #[error(transparent)]
23 Settings(SettingsError),
24 #[error(transparent)]
26 Lock(StoreLockError),
27 #[error("opening requires {field}")]
29 MissingConfiguration {
30 field: &'static str,
32 },
33 #[error(transparent)]
36 Bug(#[from] coven_foundation::task::Bug),
37}
38
39impl CarriesBug for OpenError {
40 fn bug(&self) -> Option<&Bug> {
41 match self {
42 Self::Bug(bug) => Some(bug),
43 Self::Database(error) => error.bug(),
44 Self::Lock(error) => error.bug(),
45 Self::Settings(error) => error.bug(),
46 Self::Migration(MigrationError::Failed { source, .. })
47 | Self::CovenSchema(CovenSchemaError::Failed { source }) => source.bug(),
48 Self::Migration(
49 MigrationError::NotContiguous { .. } | MigrationError::SchemaTooNew { .. },
50 )
51 | Self::CovenSchema(
52 CovenSchemaError::ReadOnly | CovenSchemaError::SchemaTooNew { .. },
53 )
54 | Self::MissingConfiguration { .. } => None,
55 }
56 }
57}
58
59impl From<SettingsError> for OpenError {
60 fn from(error: SettingsError) -> Self {
61 match error {
62 SettingsError::Bug(bug) => Self::Bug(bug),
63 error => Self::Settings(error),
64 }
65 }
66}
67
68impl From<StoreLockError> for OpenError {
69 fn from(error: StoreLockError) -> Self {
70 match error {
71 StoreLockError::Bug(bug) => Self::Bug(bug),
72 error => Self::Lock(error),
73 }
74 }
75}
76
77impl From<sqlive::rusqlite::Error> for OpenError {
78 fn from(error: sqlive::rusqlite::Error) -> Self {
79 Self::Database(error.into())
80 }
81}
82
83#[derive(Debug, thiserror::Error)]
85pub enum CovenSchemaError {
86 #[error("read-only open cannot create coven's schema")]
88 ReadOnly,
89 #[error("coven schema version {current} is newer than supported version {supported}")]
91 SchemaTooNew {
92 current: u32,
94 supported: u32,
96 },
97 #[error("creating coven's schema failed: {source}")]
99 Failed {
100 #[source]
102 source: Box<DbError>,
103 },
104}
105
106#[derive(Debug, thiserror::Error)]
108pub enum MigrationError {
109 #[error("migration at {position} has version {found}, expected {expected}")]
111 NotContiguous {
112 position: usize,
114 found: u32,
116 expected: u32,
118 },
119 #[error("schema version {current} is newer than supported version {supported}")]
121 SchemaTooNew {
122 current: u32,
124 supported: u32,
126 },
127 #[error("migration {version} ({name}) failed: {source}")]
129 Failed {
130 version: u32,
132 name: &'static str,
134 #[source]
136 source: Box<DbError>,
137 },
138}