Skip to content

Commit

Permalink
Replace Exception with less generic gNMIException
Browse files Browse the repository at this point in the history
In many places the library raises a generic Exception with a small text.
To allow the user of the library to distinguish between explicitly
raised exceptions and potential programming errors or problems by
libraries used by pygnmi we now use gNMIException instead. As no parent
exception is caught, this parameter is left blank (i.e. no exception is
wrapped).
  • Loading branch information
sebageek committed Jul 21, 2022
1 parent 367bd53 commit 380bb78
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions pygnmi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ def set(self, delete: list = None, replace: list = None,

if encoding not in encoding_set:
logger.error(f'The encoding {encoding} is not supported. The allowed are: {", ".join(encoding_set)}.')
raise Exception (f'The encoding {encoding} is not supported. The allowed are: {", ".join(encoding_set)}.')
raise gNMIException(f'The encoding {encoding} is not supported. The allowed are: {", ".join(encoding_set)}.')

# Gnmi PREFIX
try:
Expand All @@ -518,7 +518,7 @@ def set(self, delete: list = None, replace: list = None,

else:
logger.error(f'The provided input for Set message (delete operation) is not list.')
raise Exception (f'The provided input for Set message (delete operation) is not list.')
raise gNMIException(f'The provided input for Set message (delete operation) is not list.')

# Replace operation
if replace:
Expand All @@ -541,11 +541,11 @@ def set(self, delete: list = None, replace: list = None,

else:
logger.error(f'The input element for Update message must be tuple, got {ue}.')
raise Exception (f'The input element for Update message must be tuple, got {ue}.')
raise gNMIException(f'The input element for Update message must be tuple, got {ue}.')

else:
logger.error(f'The provided input for Set message (replace operation) is not list.')
raise Exception ('The provided input for Set message (replace operation) is not list.')
raise gNMIException('The provided input for Set message (replace operation) is not list.')

# Update operation
if update:
Expand All @@ -568,11 +568,11 @@ def set(self, delete: list = None, replace: list = None,

else:
logger.error(f'The input element for Update message must be tuple, got {ue}.')
raise Exception (f'The input element for Update message must be tuple, got {ue}.')
raise gNMIException(f'The input element for Update message must be tuple, got {ue}.')

else:
logger.error(f'The provided input for Set message (update operation) is not list.')
raise Exception ('The provided input for Set message (replace operation) is not list.')
raise gNMIException('The provided input for Set message (replace operation) is not list.')

try:
# Adding collection of data for diff before the change
Expand Down Expand Up @@ -796,7 +796,7 @@ def subscribe(self, subscribe: dict = None, poll: bool = False, aliases: list =
logger.info(f'Collecting Telemetry...')

if (subscribe and poll) or (subscribe and aliases) or (poll and aliases):
raise Exception('Subscribe request supports only one request at a time.')
raise gNMIException('Subscribe request supports only one request at a time.')

if poll:
if isinstance(poll, bool):
Expand Down Expand Up @@ -849,7 +849,7 @@ def subscribe2(self, subscribe: dict, target: str = None):
return self.subscribe_once(subscribe=subscribe, target=target)

else:
raise Exception('Unknown subscription request mode.')
raise gNMIException('Unknown subscription request mode.')

def subscribe_stream(self, subscribe: dict, target: str = None):
if 'mode' not in subscribe:
Expand Down

0 comments on commit 380bb78

Please sign in to comment.