@@ -91,16 +91,8 @@ def set_basis(self, collections: Collections):
9191 """
9292 Initializes the store with a full set of data, replacing any existing data.
9393 """
94- try :
95- all_decoded = {}
96- for kind in collections :
97- collection = collections [kind ]
98- items_decoded = {}
99- for key in collection :
100- items_decoded [key ] = kind .decode (collection [key ])
101- all_decoded [kind ] = items_decoded
102- except Exception as e :
103- log .error ("Failed decoding set_basis collection. Aborting" , exc_info = e )
94+ all_decoded = self .__decode_collection (collections )
95+ if all_decoded is None :
10496 return
10597
10698 try :
@@ -115,16 +107,8 @@ def apply_delta(self, collections: Collections):
115107 """
116108 Applies a delta update to the store.
117109 """
118- try :
119- all_decoded = {}
120- for kind in collections :
121- collection = collections [kind ]
122- items_decoded = {}
123- for key in collection :
124- items_decoded [key ] = kind .decode (collection [key ])
125- all_decoded [kind ] = items_decoded
126- except Exception as e :
127- log .error ("Failed decoding apply_delta collection. Aborting" , exc_info = e )
110+ all_decoded = self .__decode_collection (collections )
111+ if all_decoded is None :
128112 return
129113
130114 try :
@@ -140,6 +124,21 @@ def apply_delta(self, collections: Collections):
140124 finally :
141125 self ._lock .unlock ()
142126
127+ def __decode_collection (self , collections : Collections ) -> Optional [Dict [VersionedDataKind , Dict [str , Any ]]]:
128+ try :
129+ all_decoded = {}
130+ for kind in collections :
131+ collection = collections [kind ]
132+ items_decoded = {}
133+ for key in collection :
134+ items_decoded [key ] = kind .decode (collection [key ])
135+ all_decoded [kind ] = items_decoded
136+
137+ return all_decoded
138+ except Exception as e :
139+ log .error ("Failed decoding collection." , exc_info = e )
140+ return None
141+
143142 @property
144143 def initialized (self ) -> bool :
145144 """
0 commit comments