diff --git a/include/pyjs/pycpp/error_handling.py b/include/pyjs/pycpp/error_handling.py index 9a00f3b..7ef894a 100644 --- a/include/pyjs/pycpp/error_handling.py +++ b/include/pyjs/pycpp/error_handling.py @@ -13,6 +13,13 @@ def __init__(self, err, message=None): # default message if message is None: message = js.JSON.stringify(err, js.Object.getOwnPropertyNames(err)) + + self.name = "UnknownError" + try: + self.name = err.name + except AttributeError: + pass + self.message = message # i diff --git a/src/export_js_proxy.cpp b/src/export_js_proxy.cpp index 899dc51..c36a4c1 100644 --- a/src/export_js_proxy.cpp +++ b/src/export_js_proxy.cpp @@ -80,6 +80,21 @@ namespace pyjs { std::stringstream ss; ss << "has no attribute/key "; + + // check if key is a string + if (key->typeOf().as() == "string") + { + ss << key->as(); + } + else if (key->typeOf().as() == "number") + { + ss << key->as(); + } + else + { + ss << "[unknown key type]"; + } + throw pybind11::attribute_error(ss.str()); } return implicit_js_to_py(wrapped_return_value["ret"], type_string);