Skip to content

Commit

Permalink
Add support for retrieving error messages from inside libvyosconfig.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmbaturin committed Sep 11, 2018
1 parent bfedcd4 commit 0c82593
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion python/vyos/configtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ def __init__(self, config_string, libpath='/usr/lib/libvyosconfig.so.0'):
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
Expand Down Expand Up @@ -152,10 +156,12 @@ def __init__(self, config_string, libpath='/usr/lib/libvyosconfig.so.0'):
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)
Expand Down

0 comments on commit 0c82593

Please sign in to comment.