From 1952929dc02149f4c0123eceaf0626b91935ce62 Mon Sep 17 00:00:00 2001 From: Pallab Pain Date: Tue, 27 Aug 2024 00:30:12 +0530 Subject: [PATCH] fix(apply): prints resource name when apply or delete fails When the apply or delete command fails, it doesn't clearly mention which resource failed. This commit fixes the issue by printing the resource name along with the eror. Wrike Ticket: https://www.wrike.com/open.htm?id=1480954550 --- riocli/apply/parse.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/riocli/apply/parse.py b/riocli/apply/parse.py index c39dbf3c..f20cc8fe 100644 --- a/riocli/apply/parse.py +++ b/riocli/apply/parse.py @@ -250,7 +250,12 @@ def _apply_manifest(self, obj_key: str, *args, **kwargs) -> None: obj = self.objects[obj_key] kls = get_model(obj) - kls.validate(obj) + + try: + kls.validate(obj) + except Exception as ex: + raise Exception(f'invalid manifest {obj_key}: {str(ex)}') + ist = kls(munchify(obj)) obj_key = click.style(obj_key, bold=True) @@ -274,7 +279,7 @@ def _apply_manifest(self, obj_key: str, *args, **kwargs) -> None: except Exception as ex: message_with_prompt("{} Failed to apply {}. Error: {}".format( Symbols.ERROR, obj_key, str(ex)), fg=Colors.RED, spinner=spinner) - raise ex + raise Exception(f'{obj_key}: {str(ex)}') def _delete_manifest(self, obj_key: str, *args, **kwargs) -> None: """Instantiate and delete the object manifest""" @@ -283,7 +288,12 @@ def _delete_manifest(self, obj_key: str, *args, **kwargs) -> None: obj = self.objects[obj_key] kls = get_model(obj) - kls.validate(obj) + + try: + kls.validate(obj) + except Exception as ex: + raise Exception(f'invalid manifest {obj_key}: {str(ex)}') + ist = kls(munchify(obj)) obj_key = click.style(obj_key, bold=True) @@ -309,7 +319,7 @@ def _delete_manifest(self, obj_key: str, *args, **kwargs) -> None: except Exception as ex: message_with_prompt("{} Failed to delete {}. Error: {}".format( Symbols.ERROR, obj_key, str(ex)), fg=Colors.RED, spinner=spinner) - raise ex + raise Exception(f'{obj_key}: {str(ex)}') def _process_file_list(self, files): for f in files: