Skip to content

Commit

Permalink
Improve error-handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mpenning committed Nov 2, 2023
1 parent 7542a3b commit 9a9d01f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 5 additions & 2 deletions ciscoconfparse/ccp_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import inspect
import re

from ciscoconfparse.errors import InvalidTypecast
from ciscoconfparse.errors import InvalidTypecast, InvalidParameters
from ciscoconfparse.ccp_util import junos_unsupported
from loguru import logger

Expand Down Expand Up @@ -292,7 +292,10 @@ def text(self):
def text(self, newtext=None):
"""Set self.text, self.indent, self.line_id (and all comments' self.parent)"""
# FIXME - children do not associate correctly if this is used as-is...
assert isinstance(newtext, str)
if not isinstance(newtext, str):
error = f"text=`{newtext}` is an invalid config line"
error.critical(error)
raise InvalidParameters(error)

# escape braces since single braces could be misunderstood as
# f-string or string.format() delimiters...
Expand Down
5 changes: 2 additions & 3 deletions ciscoconfparse/ciscoconfparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def _cfgobj_from_text(
)

# if factory is **faster** than if factory is True
elif factory:
elif syntax in ALL_VALID_SYNTAX and factory:
obj = ConfigLineFactory(
txt,
comment_delimiter,
Expand All @@ -411,8 +411,7 @@ def _cfgobj_from_text(

else:
err_txt = (
"Cannot classify config list item '%s' "
"into a proper configuration object line" % txt
f"Cannot classify config list item `{txt}` into a proper configuration object line"
)
logger.error(err_txt)
raise ValueError(err_txt)
Expand Down

0 comments on commit 9a9d01f

Please sign in to comment.