Skip to content

Commit 25f93f3

Browse files
committed
Update aggreggate errors
1 parent d9227fd commit 25f93f3

File tree

1 file changed

+57
-14
lines changed

1 file changed

+57
-14
lines changed

scripts/print_aggregated_errors.py

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,80 @@
11
import os
22
import json
33

4-
ERROR_DIR = "test_output" # or "." if your files are in the current folder
4+
ERROR_DIR = "test_output" # Directory where error files are stored
55

66
def load_error_files():
7+
"""Load individual error files for each node"""
8+
if not os.path.exists(ERROR_DIR):
9+
print(f"⚠️ Error directory not found: {ERROR_DIR}")
10+
return []
11+
712
return [
813
f for f in os.listdir(ERROR_DIR)
914
if f.startswith("errors_Node_") and f.endswith(".json")
1015
]
1116

17+
def load_aggregated_error_file():
18+
"""Load the aggregated error file if it exists"""
19+
error_file_path = os.path.join(ERROR_DIR, "error_stats.json")
20+
21+
if os.path.exists(error_file_path):
22+
try:
23+
with open(error_file_path, "r") as f:
24+
return json.load(f)
25+
except Exception as e:
26+
print(f"⚠️ Failed to read aggregated error file: {str(e)}")
27+
28+
return {}
29+
1230
def print_error_summary():
1331
print("\n\n📊 Global Error Summary:\n")
1432

33+
# Try individual files first (preferred method)
1534
error_files = load_error_files()
35+
36+
if error_files:
37+
print("📁 Using individual node error files:")
38+
for filename in sorted(error_files):
39+
node_name = filename.replace("errors_", "").replace(".json", "").replace("_", " ")
40+
print(f"🔧 {node_name}")
1641

17-
for filename in sorted(error_files):
18-
node_name = filename.replace("errors_", "").replace(".json", "").replace("_", " ")
19-
print(f"🔧 {node_name}")
42+
try:
43+
with open(os.path.join(ERROR_DIR, filename), "r") as f:
44+
errors = json.load(f)
2045

21-
try:
22-
with open(os.path.join(ERROR_DIR, filename), "r") as f:
23-
errors = json.load(f)
46+
if not errors:
47+
print(" ✅ No errors")
48+
else:
49+
for message, count in errors.items():
50+
print(f" • {count}x {message}")
51+
52+
except Exception as e:
53+
print(f" ⚠️ Failed to read or parse {filename}: {str(e)}")
2454

25-
if not errors:
55+
print()
56+
57+
else:
58+
# Fallback to aggregated file
59+
print("📁 Using aggregated error file:")
60+
error_data = load_aggregated_error_file()
61+
62+
if not error_data:
63+
print("✅ No error data found")
64+
return
65+
66+
for node_name in sorted(error_data.keys()):
67+
print(f"🔧 {node_name}")
68+
69+
node_errors = error_data[node_name]
70+
71+
if not node_errors:
2672
print(" ✅ No errors")
2773
else:
28-
for message, count in errors.items():
29-
print(f" • {count}x {message}")
30-
31-
except Exception as e:
32-
print(f" ⚠️ Failed to read or parse {filename}: {str(e)}")
74+
for error_key, count in node_errors.items():
75+
print(f" • {count}x {error_key}")
3376

34-
print()
77+
print()
3578

3679
if __name__ == "__main__":
3780
print_error_summary()

0 commit comments

Comments
 (0)