55from collections import defaultdict
66from pathlib import Path
77
8+ from pydantic import ValidationError
9+
810from rules_validation_api .decorators .tracker import VALIDATORS_CALLED
911from rules_validation_api .validators .rules_validator import RulesValidation
1012
2325LEFT_COLOR = "\033 [34m" # Blue for class name
2426COLON_COLOR = "\033 [33m" # Yellow for colon
2527RIGHT_COLOR = "\033 [92m" # Milk green for validator
26- CLASS_COLORS = [
27- "\033 [34m" , # blue
28- "\033 [35m" , # magenta
29- "\033 [36m" , # cyan
30- "\033 [94m" , # light blue
31- "\033 [95m" , # light magenta
32- "\033 [96m" , # light cyan
33- "\033 [37m" , # white/light grey
34- ]
28+
29+
30+ def refine_error (e : ValidationError ) -> str :
31+ """Return a very short, single-line error message."""
32+ lines = [f"❌Validation Error: { len (e .errors ())} validation error(s)" ]
33+
34+ for err in e .errors ():
35+ loc = "." .join (str (x ) for x in err ["loc" ])
36+ msg = err ["msg" ]
37+ type_ = err ["type" ]
38+
39+ lines .append (f"{ loc } : { msg } [type={ type_ } ]" )
40+
41+ return "\n " .join (lines )
42+
3543
3644def main () -> None :
3745 parser = argparse .ArgumentParser (description = "Validate campaign configuration." )
@@ -50,25 +58,21 @@ def main() -> None:
5058 cls , method = v .split (":" , 1 )
5159 grouped [cls ].append (method .strip ())
5260
53- # Assign colors to classes
54- cls_color_map = {}
55- for i , cls_name in enumerate (sorted (grouped .keys (), reverse = True )):
56- cls_color_map [cls_name ] = CLASS_COLORS [i % len (CLASS_COLORS )]
57-
5861 # Print grouped
5962 for cls_name in sorted (grouped .keys (), reverse = True ):
6063 methods = sorted (grouped [cls_name ])
6164 # First method prints class name
6265 first = methods [0 ]
63- colored = f"{ cls_color_map [ cls_name ] } { cls_name } { RESET } { COLON_COLOR } :{ RESET } { RIGHT_COLOR } { first } { RESET } "
64- print (colored )
66+ colored = f"{ LEFT_COLOR } { cls_name } { RESET } { COLON_COLOR } :{ RESET } { RIGHT_COLOR } { first } { RESET } "
67+ sys . stdout . write (colored )
6568 # Rest methods indented
6669 for method_name in methods [1 :]:
6770 colored = f"{ ' ' * len (cls_name )} { COLON_COLOR } :{ RESET } { RIGHT_COLOR } { method_name } { RESET } "
68- print (colored )
71+ sys . stdout . write (colored )
6972
70- except ValueError as e :
71- sys .stderr .write (f"{ YELLOW } Validation Error:{ RESET } { RED } { e } { RESET } \n " )
73+ except ValidationError as e :
74+ clean = refine_error (e )
75+ sys .stderr .write (f"{ YELLOW } { clean } { RESET } \n " )
7276
7377
7478if __name__ == "__main__" :
0 commit comments