@@ -56,6 +56,18 @@ pub enum IndexeddbSerializerError {
5656 CryptoStoreError ( #[ from] CryptoStoreError ) ,
5757}
5858
59+ impl From < web_sys:: DomException > for IndexeddbSerializerError {
60+ fn from ( frm : web_sys:: DomException ) -> Self {
61+ Self :: DomException { name : frm. name ( ) , message : frm. message ( ) , code : frm. code ( ) }
62+ }
63+ }
64+
65+ impl From < serde_wasm_bindgen:: Error > for IndexeddbSerializerError {
66+ fn from ( e : serde_wasm_bindgen:: Error ) -> Self {
67+ Self :: Serialization ( serde:: de:: Error :: custom ( e. to_string ( ) ) )
68+ }
69+ }
70+
5971#[ derive( Debug , Deserialize , Serialize ) ]
6072#[ serde( untagged) ]
6173pub enum MaybeEncrypted {
@@ -107,15 +119,15 @@ impl IndexeddbSerializer {
107119 & self ,
108120 table_name : & str ,
109121 key : T ,
110- ) -> Result < IdbKeyRange , IndexeddbCryptoStoreError >
122+ ) -> Result < IdbKeyRange , IndexeddbSerializerError >
111123 where
112124 T : SafeEncode ,
113125 {
114126 match & self . store_cipher {
115127 Some ( cipher) => key. encode_to_range_secure ( table_name, cipher) ,
116128 None => key. encode_to_range ( ) ,
117129 }
118- . map_err ( |e| IndexeddbCryptoStoreError :: DomException {
130+ . map_err ( |e| IndexeddbSerializerError :: DomException {
119131 code : 0 ,
120132 name : "IdbKeyRangeMakeError" . to_owned ( ) ,
121133 message : e,
@@ -130,7 +142,7 @@ impl IndexeddbSerializer {
130142 pub fn serialize_value (
131143 & self ,
132144 value : & impl Serialize ,
133- ) -> Result < JsValue , IndexeddbCryptoStoreError > {
145+ ) -> Result < JsValue , IndexeddbSerializerError > {
134146 let serialized = self . maybe_encrypt_value ( value) ?;
135147 Ok ( serde_wasm_bindgen:: to_value ( & serialized) ?)
136148 }
@@ -184,7 +196,7 @@ impl IndexeddbSerializer {
184196 pub fn deserialize_value < T : DeserializeOwned > (
185197 & self ,
186198 value : JsValue ,
187- ) -> Result < T , IndexeddbCryptoStoreError > {
199+ ) -> Result < T , IndexeddbSerializerError > {
188200 // Objects which are serialized nowadays should be represented as a
189201 // `MaybeEncrypted`. However, `serialize_value` previously used a
190202 // different format, so we need to handle that in case we have old data.
@@ -238,11 +250,11 @@ impl IndexeddbSerializer {
238250 pub fn deserialize_legacy_value < T : DeserializeOwned > (
239251 & self ,
240252 value : JsValue ,
241- ) -> Result < T , IndexeddbCryptoStoreError > {
253+ ) -> Result < T , IndexeddbSerializerError > {
242254 match & self . store_cipher {
243255 Some ( cipher) => {
244256 if !value. is_array ( ) {
245- return Err ( IndexeddbCryptoStoreError :: CryptoStoreError (
257+ return Err ( IndexeddbSerializerError :: CryptoStoreError (
246258 CryptoStoreError :: UnpicklingError ,
247259 ) ) ;
248260 }
0 commit comments