diff options
author | Daniil Baturin <daniil@baturin.org> | 2018-09-10 16:45:59 +0200 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2018-09-10 16:45:59 +0200 |
commit | 05e275a1503a4ddd4485b15519c0779fbd095a56 (patch) | |
tree | c446954417f6176f873a4dea1812001b753a2c20 /python/vyos/configtree.py | |
parent | c0f32e28eb972697aa11a4cf9912f457c51f0c10 (diff) | |
download | vyos-1x-05e275a1503a4ddd4485b15519c0779fbd095a56.tar.gz vyos-1x-05e275a1503a4ddd4485b15519c0779fbd095a56.zip |
Improve error reporting in vyos.configtree
Diffstat (limited to 'python/vyos/configtree.py')
-rw-r--r-- | python/vyos/configtree.py | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/python/vyos/configtree.py b/python/vyos/configtree.py index ad8fcef1a..463aa5e95 100644 --- a/python/vyos/configtree.py +++ b/python/vyos/configtree.py @@ -24,6 +24,7 @@ def strip_comments(s): IN_COMMENT = 1 i = len(s) - 1 + state = INITIAL config_end = 0 @@ -42,14 +43,11 @@ def strip_comments(s): break elif (state == INITIAL) and (c == '/'): # A comment begins, or it's a stray slash - try: - if (s[i-1] == '*'): - state = IN_COMMENT - i -= 2 - else: - raise ValueError("Invalid syntax") - except: - raise ValueError("Invalid syntax") + if (s[i-1] == '*'): + state = IN_COMMENT + i -= 2 + else: + raise ValueError("Invalid syntax: stray slash at character {0}".format(i + 1)) elif (state == INITIAL) and (c == '}'): # We are not inside a comment, that's the end of the last node config_end = i + 1 @@ -61,12 +59,12 @@ def strip_comments(s): state = INITIAL i -= 2 except: - raise ValueError("Invalid syntax") + raise ValueError("Invalid syntax: malformed commend end at character {0}".format(i + 1)) elif (state == IN_COMMENT) and (c != '*'): # Ignore everything inside comments, including braces i -= 1 else: - raise ValueError("Invalid syntax") + raise ValueError("Invalid syntax at character {0}: invalid character {1}".format(i + 1, c)) return (s[0:config_end], s[config_end+1:]) |