22from __future__ import annotations
33import os
44import time
5+ import traceback
56import concurrent .futures
67from dataclasses import dataclass
78from typing import Any
@@ -222,6 +223,8 @@ def _run_magic_item_comparison(pdf_path: str, document: str) -> ComparisonResult
222223 return compare_records ("magic_items" , pdf_records , db_records , SKIP_FIELDS ["magic_items" ])
223224
224225
226+ # "items" (adventuring gear) is not in _RUNNERS because the SRD adventuring gear
227+ # items do not have a dedicated model in api_v2 that maps cleanly to PDF records.
225228_RUNNERS = {
226229 "spells" : _run_spell_comparison ,
227230 "creatures" : _run_creature_comparison ,
@@ -239,7 +242,10 @@ def _run_magic_item_comparison(pdf_path: str, document: str) -> ComparisonResult
239242def _render_results (results : dict [str , ComparisonResult ], elapsed : float ) -> None :
240243 console = Console ()
241244
242- summary = Table (title = f"SRD 5.2 PDF vs Database (completed in { elapsed :.1f} s)" )
245+ def _fmt (n ):
246+ return "[green]0[/green]" if n == 0 else str (n )
247+
248+ summary = Table (title = f"SRD 5.2 PDF vs Database (completed in { elapsed :.1f} s)" )
243249 summary .add_column ("Entity type" , style = "bold" )
244250 summary .add_column ("In PDF" , justify = "right" )
245251 summary .add_column ("In DB" , justify = "right" )
@@ -248,8 +254,6 @@ def _render_results(results: dict[str, ComparisonResult], elapsed: float) -> Non
248254 summary .add_column ("Mismatches" , justify = "right" )
249255
250256 for name , result in results .items ():
251- def _fmt (n ):
252- return f"[green]0[/green]" if n == 0 else str (n )
253257 summary .add_row (
254258 name ,
255259 str (result .pdf_count ),
@@ -328,6 +332,8 @@ def handle(self, *args, **options):
328332 start = time .monotonic ()
329333 results : dict [str , ComparisonResult ] = {}
330334
335+ failed : list [str ] = []
336+
331337 with concurrent .futures .ThreadPoolExecutor () as executor :
332338 futures = {
333339 executor .submit (_RUNNERS [etype ], pdf_path , document ): etype
@@ -339,6 +345,11 @@ def handle(self, *args, **options):
339345 results [etype ] = future .result ()
340346 except Exception as exc :
341347 self .stderr .write (f" ERROR comparing { etype } : { exc } " )
348+ traceback .print_exc ()
349+ failed .append (etype )
350+
351+ if failed :
352+ raise CommandError (f"Comparisons failed for: { ', ' .join (failed )} " )
342353
343354 elapsed = time .monotonic () - start
344355 _render_results (
0 commit comments