11#include < pybind11/pybind11.h>
2- // #include <tiledb/tiledb_experimental>
32#include < tiledb/tiledb.h>
43#include < tiledb/tiledb_experimental.h>
54
@@ -17,6 +16,37 @@ typedef struct {
1716
1817using ArraySchemaEvolution = PyArraySchemaEvolution;
1918
19+ void _throw_tiledb_error (tiledb_error_t *err_ptr) {
20+ const char *err_msg_ptr = NULL ;
21+ int ret = tiledb_error_message (err_ptr, &err_msg_ptr);
22+ if (ret != TILEDB_OK) {
23+ tiledb_error_free (&err_ptr);
24+ if (ret == TILEDB_OOM) {
25+ throw std::bad_alloc ();
26+ }
27+ TPY_ERROR_LOC (" error retrieving error message" );
28+ }
29+
30+ TPY_ERROR_LOC (std::string (err_msg_ptr));
31+ }
32+
33+ void _throw_ctx_err (tiledb_ctx_t *ctx_ptr, int rc) {
34+ if (rc == TILEDB_OK)
35+ return ;
36+ if (rc == TILEDB_OOM)
37+ throw std::bad_alloc ();
38+
39+ tiledb_error_t *err_ptr = NULL ;
40+ int ret = tiledb_ctx_get_last_error (ctx_ptr, &err_ptr);
41+ if (ret != TILEDB_OK) {
42+ tiledb_error_free (&err_ptr);
43+ if (ret == TILEDB_OOM)
44+ throw std::bad_alloc ();
45+ TPY_ERROR_LOC (" error retrieving error object from ctx" );
46+ }
47+ _throw_tiledb_error (err_ptr);
48+ }
49+
2050void init_schema_evolution (py::module &m) {
2151 py::class_<ArraySchemaEvolution>(m, " ArraySchemaEvolution" )
2252 .def (py::init ([](py::object ctx_py) {
@@ -27,7 +57,7 @@ void init_schema_evolution(py::module &m) {
2757 tiledb_array_schema_evolution_t *evol_p;
2858 int rc = tiledb_array_schema_evolution_alloc (ctx_c, &evol_p);
2959 if (rc != TILEDB_OK) {
30- TPY_ERROR_LOC ( " Failed to allocate ArraySchemaEvolution " );
60+ _throw_ctx_err (ctx_c, rc );
3161 }
3262
3363 return new PyArraySchemaEvolution ({ctx_c, evol_p});
@@ -42,22 +72,21 @@ void init_schema_evolution(py::module &m) {
4272 int rc = tiledb_array_schema_evolution_add_attribute (
4373 inst.ctx_ , inst.evol_ , attr_c);
4474 if (rc != TILEDB_OK) {
45- TPY_ERROR_LOC ( " Failed to add attribute to ArraySchemaEvolution " );
75+ _throw_ctx_err (inst. ctx_ , rc );
4676 }
4777 })
4878 .def (" drop_attribute" ,
4979 [](ArraySchemaEvolution &inst, std::string attr_name) {
5080 int rc = tiledb_array_schema_evolution_drop_attribute (
5181 inst.ctx_ , inst.evol_ , attr_name.c_str ());
5282 if (rc != TILEDB_OK) {
53- TPY_ERROR_LOC (
54- " Failed to drop attribute from ArraySchemaEvolution" );
83+ _throw_ctx_err (inst.ctx_ , rc);
5584 }
5685 })
5786 .def (" array_evolve" , [](ArraySchemaEvolution &inst, std::string uri) {
5887 int rc = tiledb_array_evolve (inst.ctx_ , uri.c_str (), inst.evol_ );
5988 if (rc != TILEDB_OK) {
60- TPY_ERROR_LOC ( " Failed to drop attribute from ArraySchemaEvolution " );
89+ _throw_ctx_err (inst. ctx_ , rc );
6190 }
6291 });
6392}
0 commit comments