Skip to content

Commit

Permalink
better error handling (#56)
Browse files Browse the repository at this point in the history
* better errror handling
  • Loading branch information
DerThorsten authored Feb 14, 2024
1 parent 8c285b1 commit 4c14bc9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/pyjs/pycpp/error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions src/export_js_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,21 @@ namespace pyjs
{
std::stringstream ss;
ss << "has no attribute/key ";

// check if key is a string
if (key->typeOf().as<std::string>() == "string")
{
ss << key->as<std::string>();
}
else if (key->typeOf().as<std::string>() == "number")
{
ss << key->as<int>();
}
else
{
ss << "[unknown key type]";
}

throw pybind11::attribute_error(ss.str());
}
return implicit_js_to_py(wrapped_return_value["ret"], type_string);
Expand Down

0 comments on commit 4c14bc9

Please sign in to comment.