Skip to content

Commit 2a1d68f

Browse files
authored
Use AlmdrlibValueError instead of Exception (#108)
Printing of Exceptions is not safe and AlmdrlibValueError should have been used in the first place. ``` alcli --profile integration aetuner update_tagset --account_id 134249387 --path tuning/ngx/ConfigChange/AttackerKeyAccountNameWhitelist --xtuning '[{"type":"test","operation":"delete","path":"tuning/ngx/ConfigChange/AttackerKeyAccountNameWhitelist","key":"config_change"]}]' --reason "wrong type" --dry_run=true ERROR:root:Expecting ',' delimiter: line 1 column 124 (char 123) ERROR:alcli.almdr_cli:An exception of type Exception occurred. Arguments: ('<aetuner.update_tagset: POST /v1/{account_id}/tagsets> failed Validation Error: \'[{"type":"test","operation":"delete","path":"tuning/ngx/ConfigChange/AttackerKeyAccountNameWhitelist","key":"config_change"]}]\' is not of type \'array\'',) Traceback (most recent call last): File "/Users/acockfield/Library/Python/3.9/lib/python/site-packages/almdrlib/client.py", line 694, in __call__ return self._call(*args, **kwargs) File "/Users/acockfield/Library/Python/3.9/lib/python/site-packages/almdrlib/client.py", line 670, in f self._body.serialize(headers, kwargs) File "/Users/acockfield/Library/Python/3.9/lib/python/site-packages/almdrlib/client.py", line 314, in serialize payload_body_param.serialize(kwargs, headers) File "/Users/acockfield/Library/Python/3.9/lib/python/site-packages/almdrlib/client.py", line 227, in serialize self.validate(result) File "/Users/acockfield/Library/Python/3.9/lib/python/site-packages/almdrlib/client.py", line 127, in validate raise AlmdrlibValueError(f"Validation Error: {e.message}") from None almdrlib.exceptions.AlmdrlibValueError: Validation Error: '[{"type":"test","operation":"delete","path":"tuning/ngx/ConfigChange/AttackerKeyAccountNameWhitelist","key":"config_change"]}]' is not of type 'array' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/acockfield/Library/Python/3.9/lib/python/site-packages/alcli/alertlogic_cli.py", line 116, in main return services[parsed_args.service](remaining, parsed_args) File "/Users/acockfield/Library/Python/3.9/lib/python/site-packages/alcli/alertlogic_cli.py", line 199, in __call__ res = operation(**op_args) File "/Users/acockfield/Library/Python/3.9/lib/python/site-packages/almdrlib/client.py", line 696, in __call__ raise Exception(f"{self} failed {e}") Exception: <aetuner.update_tagset: POST /v1/{account_id}/tagsets> failed Validation Error: '[{"type":"test","operation":"delete","path":"tuning/ngx/ConfigChange/AttackerKeyAccountNameWhitelist","key":"config_change"]}]' is not of type 'array ```
1 parent e8d9242 commit 2a1d68f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

almdrlib/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,8 @@ def __call__(self, *args, **kwargs):
692692
self._call = self._gen_call()
693693
try:
694694
return self._call(*args, **kwargs)
695-
except Exception as e:
696-
raise Exception(f"{self} failed {e}")
695+
except AlmdrlibValueError as e:
696+
raise AlmdrlibValueError(f'{self} failed {e}')
697697

698698
def __repr__(self):
699699
return f"<{self._client.name}.{self.operation_id}: " \

0 commit comments

Comments
 (0)