77from ..async_typer import AsyncTyper
88from ..ctl .client import initialize_client
99from ..ctl .utils import catch_exception , init_logging
10+ from ..exceptions import ValidationError
1011from ..spec .object import ObjectFile
1112from .parameters import CONFIG_PARAM
1213from .utils import load_yamlfile_from_disk_and_exit
@@ -39,8 +40,21 @@ async def load(
3940 files = load_yamlfile_from_disk_and_exit (paths = paths , file_type = ObjectFile , console = console )
4041 client = initialize_client ()
4142
43+ has_errors = False
44+
4245 for file in files :
43- await file .validate_format (client = client , branch = branch )
46+ try :
47+ await file .validate_format (client = client , branch = branch )
48+ except ValidationError as e :
49+ has_errors = True
50+ if file .multiple_documents :
51+ console .print (f"[red] File '{ file .location } ' [{ file .document_position } ] is not valid!" )
52+ else :
53+ console .print (f"[red] File '{ file .location } ' is not valid!" )
54+ console .print (f"[red] { e .message } " )
55+
56+ if has_errors :
57+ raise typer .Exit (1 )
4458
4559 for file in files :
4660 await file .process (client = client , branch = branch )
@@ -63,5 +77,21 @@ async def validate(
6377 files = load_yamlfile_from_disk_and_exit (paths = paths , file_type = ObjectFile , console = console )
6478 client = initialize_client ()
6579
80+ has_errors = False
6681 for file in files :
67- await file .validate_format (client = client , branch = branch )
82+ try :
83+ await file .validate_format (client = client , branch = branch )
84+ if file .multiple_documents :
85+ console .print (f"[green] File '{ file .location } ' [{ file .document_position } ] is Valid!" )
86+ else :
87+ console .print (f"[green] File '{ file .location } ' is Valid!" )
88+ except ValidationError as e :
89+ has_errors = True
90+ if file .multiple_documents :
91+ console .print (f"[red] File '{ file .location } ' [{ file .document_position } ] is not valid!" )
92+ else :
93+ console .print (f"[red] File '{ file .location } ' is not valid!" )
94+ console .print (f"[red] { e .message } " )
95+
96+ if has_errors :
97+ raise typer .Exit (1 )
0 commit comments