Skip to content

Commit

Permalink
Add MismatchedType() error
Browse files Browse the repository at this point in the history
  • Loading branch information
mpenning committed Oct 20, 2023
1 parent 0541042 commit 16e29b3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 8 additions & 2 deletions ciscoconfparse/ccp_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
from loguru import logger

from ciscoconfparse.protocol_values import ASA_TCP_PORTS, ASA_UDP_PORTS
from ciscoconfparse.errors import InvalidParameters, InvalidMember, MismatchedType
from ciscoconfparse.errors import InvalidShellVariableMapping
from ciscoconfparse.errors import InvalidParameters, InvalidMember
from ciscoconfparse.errors import PythonOptimizeException
from ciscoconfparse.errors import DynamicAddressException
from ciscoconfparse.errors import ListItemMissingAttribute
Expand Down Expand Up @@ -4045,8 +4045,14 @@ def remove(self, arg):
if len(new_list) < length_before:
self._list = new_list
break
arg_type = type(arg)
if len(new_list) == length_before:
raise invalidMember(arg)
if arg_type is not type(self._list[0]):
# Do a simple type check to see if typing is the problem...
raise MismatchedType(arg)
else:
# Otherwise, flag the problem as an invalid member...
raise invalidMember(arg)
return self


Expand Down
6 changes: 6 additions & 0 deletions ciscoconfparse/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,9 @@ class InvalidMember(Exception):
def __init__(self, msg=""):
super().__init__(msg)
self.msg = msg

class MismatchedType(Exception):

def __init__(self, msg=""):
super().__init__(msg)
self.msg = msg

0 comments on commit 16e29b3

Please sign in to comment.