diff options
author | John Estabrook <jestabro@vyos.io> | 2023-08-09 09:03:28 -0500 |
---|---|---|
committer | John Estabrook <jestabro@vyos.io> | 2023-08-09 09:03:28 -0500 |
commit | e4b932ed0a140c9ced9a4eb501d520560b125406 (patch) | |
tree | e9834ad4b9ea9a04f0f89bd98b0b463e14dada65 /python/vyos | |
parent | 9acce7a3c7c87139de291d39c69a90801ac25691 (diff) | |
download | vyos-1x-e4b932ed0a140c9ced9a4eb501d520560b125406.tar.gz vyos-1x-e4b932ed0a140c9ced9a4eb501d520560b125406.zip |
xml: T5452: catch lib errors in generate_cache
Diffstat (limited to 'python/vyos')
-rw-r--r-- | python/vyos/configtree.py | 18 | ||||
-rw-r--r-- | python/vyos/xml_ref/__init__.py | 8 |
2 files changed, 16 insertions, 10 deletions
diff --git a/python/vyos/configtree.py b/python/vyos/configtree.py index e18d9817d..09cfd43d3 100644 --- a/python/vyos/configtree.py +++ b/python/vyos/configtree.py @@ -383,14 +383,16 @@ def union(left, right, libpath=LIBPATH): return tree def reference_tree_to_json(from_dir, to_file, libpath=LIBPATH): - __lib = cdll.LoadLibrary(libpath) - __reference_tree_to_json = __lib.reference_tree_to_json - __reference_tree_to_json.argtypes = [c_char_p, c_char_p] - __get_error = __lib.get_error - __get_error.argtypes = [] - __get_error.restype = c_char_p - - res = __reference_tree_to_json(from_dir.encode(), to_file.encode()) + try: + __lib = cdll.LoadLibrary(libpath) + __reference_tree_to_json = __lib.reference_tree_to_json + __reference_tree_to_json.argtypes = [c_char_p, c_char_p] + __get_error = __lib.get_error + __get_error.argtypes = [] + __get_error.restype = c_char_p + res = __reference_tree_to_json(from_dir.encode(), to_file.encode()) + except Exception as e: + raise ConfigTreeError(e) if res == 1: msg = __get_error().decode() raise ConfigTreeError(msg) diff --git a/python/vyos/xml_ref/__init__.py b/python/vyos/xml_ref/__init__.py index 02bbaffd8..bf434865d 100644 --- a/python/vyos/xml_ref/__init__.py +++ b/python/vyos/xml_ref/__init__.py @@ -27,11 +27,15 @@ def load_reference(cache=[]): try: from vyos.xml_ref.cache import reference - xml.define(reference) - cache.append(xml) except Exception: raise ImportError('no xml reference cache !!') + if not reference: + raise ValueError('empty xml reference cache !!') + + xml.define(reference) + cache.append(xml) + return xml def is_tag(path: list) -> bool: |