From 45f536a701107c1c2c5c6acb22b62737f6b634b1 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Wed, 19 Dec 2018 17:40:55 +0100 Subject: Fix exception propagation in python dictToConfig --- python/astra/utils.pxd | 2 +- python/astra/utils.pyx | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'python/astra') diff --git a/python/astra/utils.pxd b/python/astra/utils.pxd index e91ed98..ea3da86 100644 --- a/python/astra/utils.pxd +++ b/python/astra/utils.pxd @@ -32,4 +32,4 @@ from .PyXMLDocument cimport XMLNode from .PyIncludes cimport * cdef configToDict(Config *) -cdef Config * dictToConfig(string rootname, dc) +cdef Config * dictToConfig(string rootname, dc) except NULL diff --git a/python/astra/utils.pyx b/python/astra/utils.pyx index 46be462..b534d72 100644 --- a/python/astra/utils.pyx +++ b/python/astra/utils.pyx @@ -26,6 +26,7 @@ # distutils: language = c++ # distutils: libraries = astra +import sys cimport numpy as np import numpy as np import six @@ -45,15 +46,15 @@ from .PyXMLDocument cimport XMLNode from .PyIncludes cimport * -cdef Config * dictToConfig(string rootname, dc): +cdef Config * dictToConfig(string rootname, dc) except NULL: cdef Config * cfg = new Config() cfg.initialize(rootname) try: readDict(cfg.self, dc) - except Exception as e: + except Exception: del cfg - six.print_(e.strerror) - return NULL + exc = sys.exc_info() + raise exc[0], exc[1], exc[2] return cfg def convert_item(item): @@ -85,7 +86,7 @@ def wrap_from_bytes(value): return s -cdef void readDict(XMLNode root, _dc): +cdef bool readDict(XMLNode root, _dc) except False: cdef XMLNode listbase cdef XMLNode itm cdef int i @@ -122,8 +123,9 @@ cdef void readDict(XMLNode root, _dc): if isinstance(val, builtins.bool): val = int(val) itm = root.addChildNode(item, wrap_to_bytes(val)) + return True -cdef void readOptions(XMLNode node, dc): +cdef bool readOptions(XMLNode node, dc) except False: cdef XMLNode listbase cdef XMLNode itm cdef int i @@ -152,6 +154,7 @@ cdef void readOptions(XMLNode node, dc): if isinstance(val, builtins.bool): val = int(val) node.addOption(item, wrap_to_bytes(val)) + return True cdef configToDict(Config *cfg): return XMLNode2dict(cfg.self) -- cgit v1.2.3