From 0c8259382f51969ff789a3d2bd341d3f1e0687e0 Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Tue, 11 Sep 2018 14:49:52 +0200 Subject: Add support for retrieving error messages from inside libvyosconfig. --- python/vyos/configtree.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'python/vyos') diff --git a/python/vyos/configtree.py b/python/vyos/configtree.py index 463aa5e95..39fe41669 100644 --- a/python/vyos/configtree.py +++ b/python/vyos/configtree.py @@ -90,6 +90,10 @@ class ConfigTree(object): self.__from_string.argtypes = [c_char_p] self.__from_string.restype = c_void_p + self.__get_error = self.__lib.get_error + self.__get_error.argtypes = [] + self.__get_error.restype = c_char_p + self.__to_string = self.__lib.to_string self.__to_string.argtypes = [c_void_p] self.__to_string.restype = c_char_p @@ -152,10 +156,12 @@ class ConfigTree(object): config_section, comments_section = strip_comments(config_string) config = self.__from_string(config_section.encode()) if config is None: - raise ValueError("Parse error") + msg = self.__get_error().decode() + raise ValueError("Failed to parse config: {0}".format(msg)) else: self.__config = config self.__comments = comments_section + def __del__(self): if self.__config is not None: self.__destroy(self.__config) -- cgit v1.2.3