From 16e29b356c1dcfafcac9278c1694634d895cb926 Mon Sep 17 00:00:00 2001 From: mpenning Date: Fri, 20 Oct 2023 06:11:09 -0500 Subject: [PATCH] Add MismatchedType() error --- ciscoconfparse/ccp_util.py | 10 ++++++++-- ciscoconfparse/errors.py | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ciscoconfparse/ccp_util.py b/ciscoconfparse/ccp_util.py index f2da8e56..6d71adc1 100644 --- a/ciscoconfparse/ccp_util.py +++ b/ciscoconfparse/ccp_util.py @@ -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 @@ -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 diff --git a/ciscoconfparse/errors.py b/ciscoconfparse/errors.py index 5b7e9fa7..ca3bacbe 100644 --- a/ciscoconfparse/errors.py +++ b/ciscoconfparse/errors.py @@ -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