3333# Tests monkeypatch this path; keep in sync with utils.export_state_store.
3434_STATE_FILE = EXPORT_STATE_FILE
3535
36+ _EXPORT_ERRORS = (
37+ json .JSONDecodeError ,
38+ KeyError ,
39+ ValueError ,
40+ OSError ,
41+ FileNotFoundError ,
42+ )
43+
3644
3745def _state_lock ():
3846 return export_state_lock (_STATE_FILE )
@@ -159,7 +167,7 @@ def bulk_export():
159167 )
160168 new_sessions_map [sid ] = sess_info .get ("modified" , 0 )
161169 count += 1
162- except Exception as e :
170+ except _EXPORT_ERRORS as e :
163171 current_app .logger .warning (
164172 "Failed to export %s: %s" , sid [:10 ], e
165173 )
@@ -221,7 +229,7 @@ def bulk_export():
221229 )
222230 new_sessions_map [sid ] = sess_info .get ("modified" , 0 )
223231 count += 1
224- except Exception as e :
232+ except _EXPORT_ERRORS as e :
225233 current_app .logger .warning (
226234 "Failed to export %s: %s" , sid [:10 ], e
227235 )
@@ -232,9 +240,6 @@ def bulk_export():
232240 )
233241 zf .writestr ("manifest.jsonl" , manifest_str )
234242
235- if count > 0 :
236- _write_state (new_sessions_map , count )
237-
238243 if count == 0 :
239244 return error_response (
240245 ErrorCode .EXPORT_NOTHING_TO_EXPORT ,
@@ -243,6 +248,8 @@ def bulk_export():
243248 since = since ,
244249 )
245250
251+ _write_state (new_sessions_map , count )
252+
246253 buf .seek (0 )
247254 date_tag = datetime .now ().strftime ("%Y-%m-%d" )
248255 if since == "last" :
@@ -286,7 +293,7 @@ def export_session(project_name, session_id):
286293 fmt = request .args .get ("format" , "md" )
287294 try :
288295 session = parse_session (filepath )
289- except Exception :
296+ except _EXPORT_ERRORS :
290297 current_app .logger .exception (
291298 "Failed to parse session %s for export" , session_id
292299 )
@@ -306,7 +313,7 @@ def export_session(project_name, session_id):
306313
307314 try :
308315 stats = compute_stats (session )
309- except Exception :
316+ except _EXPORT_ERRORS :
310317 current_app .logger .exception (
311318 "Failed to compute stats for export %s" , session_id
312319 )
0 commit comments