idb_sys/
error.rs

1use js_sys::Object;
2use thiserror::Error;
3use wasm_bindgen::{JsCast, JsValue};
4
5/// Error type for [`idb-sys`](crate) crate.
6#[derive(Debug, Error, PartialEq)]
7pub enum Error {
8    /// Failed to add a value
9    #[error("failed to add a value: {}", js_object_display(.0))]
10    AddFailed(JsValue),
11
12    /// Failed to clear object store
13    #[error("failed to clear object store: {}", js_object_display(.0))]
14    ClearFailed(JsValue),
15
16    /// Failed to get count of records
17    #[error("failed to get count of records: {}", js_object_display(.0))]
18    CountFailed(JsValue),
19
20    /// Failed to advance cursor
21    #[error("failed to advance cursor: {}", js_object_display(.0))]
22    CursorAdvanceFailed(JsValue),
23
24    /// Failed to continue cursor
25    #[error("failed to continue cursor: {}", js_object_display(.0))]
26    CursorContinueFailed(JsValue),
27
28    /// Failed to get cursor key
29    #[error("failed to get cursor key: {}", js_object_display(.0))]
30    CursorKeyNotFound(JsValue),
31
32    /// Failed to get cursor primary key
33    #[error("failed to get cursor primary key: {}", js_object_display(.0))]
34    CursorPrimaryKeyNotFound(JsValue),
35
36    /// Failed to get cursor value
37    #[error("failed to get cursor value: {}", js_object_display(.0))]
38    CursorValueNotFound(JsValue),
39
40    /// Failed to delete a value
41    #[error("failed to delete a value: {}", js_object_display(.0))]
42    DeleteFailed(JsValue),
43
44    /// Failed to get event target
45    #[error("failed to get event target")]
46    EventTargetNotFound,
47
48    /// Failed to get all values
49    #[error("failed to get all values: {}", js_object_display(.0))]
50    GetAllFailed(JsValue),
51
52    /// Failed to get all keys
53    #[error("failed to get all keys: {}", js_object_display(.0))]
54    GetAllKeysFailed(JsValue),
55
56    /// Failed to get a value
57    #[error("failed to get a value: {}", js_object_display(.0))]
58    GetFailed(JsValue),
59
60    /// Failed to get a key
61    #[error("failed to get a key: {}", js_object_display(.0))]
62    GetKeyFailed(JsValue),
63
64    /// Failed to create new index
65    #[error("failed to create new index: {}", js_object_display(.0))]
66    IndexCreateFailed(JsValue),
67
68    /// Failed to delete index
69    #[error("failed to delete index: {}", js_object_display(.0))]
70    IndexDeleteFailed(JsValue),
71
72    /// Failed to delete indexed db
73    #[error("failed to delete indexed db: {}", js_object_display(.0))]
74    IndexedDbDeleteFailed(JsValue),
75
76    /// Indexed db not found
77    #[error("indexed db not found")]
78    IndexedDbNotFound(JsValue),
79
80    /// Failed to open indexed db
81    #[error("failed to open indexed db: {}", js_object_display(.0))]
82    IndexedDbOpenFailed(JsValue),
83
84    /// Failed to get index
85    #[error("failed to get index: {}", js_object_display(.0))]
86    IndexNotFound(JsValue),
87
88    /// Invalid cursor direction
89    #[error("invalid cursor direction")]
90    InvalidCursorDirection,
91
92    /// Invalid key path of an object store
93    #[error("invalid key path of an object store")]
94    InvalidKeyPath,
95
96    /// Invalid request ready state
97    #[error("invalid request ready state")]
98    InvalidReqeustReadyState,
99
100    /// Invalid storage type
101    #[error("invalid storage type")]
102    InvalidStorageType,
103
104    /// Invalid transaction mode
105    #[error("invalid transaction mode")]
106    InvalidTransactionMode,
107
108    /// Failed to get key path of an object store
109    #[error("failed to get key path of an object store: {}", js_object_display(.0))]
110    KeyPathNotFound(JsValue),
111
112    /// Failed to get key range bound
113    #[error("failed to get key range bound: {}", js_object_display(.0))]
114    KeyRangeBoundNotFound(JsValue),
115
116    /// Failed to create key range
117    #[error("failed to create key range: {}", js_object_display(.0))]
118    KeyRangeCreateFailed(JsValue),
119
120    /// Failed to check if a value is included in key range
121    #[error("failed to check if a value is included in key range: {}", js_object_display(.0))]
122    KeyRangeIncludesFailed(JsValue),
123
124    /// Number conversion error
125    #[error("number conversion error")]
126    NumberConversionError,
127
128    /// Failed to create new object store
129    #[error("failed to create new object store: {}", js_object_display(.0))]
130    ObjectStoreCreateFailed(JsValue),
131
132    /// Failed to delete object store
133    #[error("failed to delete object store: {}", js_object_display(.0))]
134    ObjectStoreDeleteFailed(JsValue),
135
136    /// Failed to get object store
137    #[error("failed to get object store: {}", js_object_display(.0))]
138    ObjectStoreNotFound(JsValue),
139
140    /// Failed to open cursor
141    #[error("failed to open cursor: {}", js_object_display(.0))]
142    OpenCursorFailed(JsValue),
143
144    /// Failed to open key cursor
145    #[error("failed to open key cursor: {}", js_object_display(.0))]
146    OpenKeyCursorFailed(JsValue),
147
148    /// Failed to get request error
149    #[error("failed to get request error: {}", js_object_display(.0))]
150    RequestErrorNotFound(JsValue),
151
152    /// Failed to get request result
153    #[error("failed to get request source: {}", js_object_display(.0))]
154    RequestResultNotFound(JsValue),
155
156    /// Failed to get request result
157    #[error("failed to get request source")]
158    RequestSourceNotFound,
159
160    /// Failed to abort transaction
161    #[error("failed to abort transaction: {}", js_object_display(.0))]
162    TransactionAbortError(JsValue),
163
164    /// Failed to commit transaction
165    #[error("failed to commit transaction: {}", js_object_display(.0))]
166    TransactionCommitError(JsValue),
167
168    /// Failed to get transaction mode
169    #[error("failed to get transaction mode: {}", js_object_display(.0))]
170    TransactionModeNotFound(JsValue),
171
172    /// Failed to open new transaction
173    #[error("failed to open new transaction: {}", js_object_display(.0))]
174    TransactionOpenFailed(JsValue),
175
176    /// Unexpected JS type
177    #[error("unexpected JS type. expected: {}, found: {}", .0, js_object_display(.1))]
178    UnexpectedJsType(&'static str, JsValue),
179
180    /// Failed to update a value
181    #[error("failed to update a value: {}", js_object_display(.0))]
182    UpdateFailed(JsValue),
183}
184
185fn js_object_display(option: &JsValue) -> String {
186    let object: &Object = option.unchecked_ref();
187    ToString::to_string(&object.to_string())
188}