Skip to content

Commit

Permalink
Rethrow a more informative error if cell kind is not a cell_kind (#…
Browse files Browse the repository at this point in the history
…2219)

Fixes #2138.
  • Loading branch information
thorstenhater authored Sep 19, 2023
1 parent faeacdd commit b099391
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion python/recipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ void register_recipe(pybind11::module& m) {
.def("cell_description", &py_recipe::cell_description, pybind11::return_value_policy::copy,
"gid"_a,
"High level description of the cell with global identifier gid.")
.def("cell_kind", &py_recipe::cell_kind,
.def("cell_kind",
&py_recipe::cell_kind,
"gid"_a,
"The kind of cell with global identifier gid.")
.def("event_generators", &py_recipe::event_generators,
Expand Down
7 changes: 6 additions & 1 deletion python/recipe.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ class py_recipe_trampoline: public py_recipe {
}

arb::cell_kind cell_kind(arb::cell_gid_type gid) const override {
PYBIND11_OVERRIDE_PURE(arb::cell_kind, py_recipe, cell_kind, gid);
try {
PYBIND11_OVERRIDE_PURE(arb::cell_kind, py_recipe, cell_kind, gid);
}
catch (const pybind11::cast_error& e) {
throw pybind11::type_error{"Couldn't convert return value of recipe.cell_kind(gid) to a cell_kind. Please check your recipe."};
}
}

std::vector<pybind11::object> event_generators(arb::cell_gid_type gid) const override {
Expand Down

0 comments on commit b099391

Please sign in to comment.