TileDB-Inc / TileDB-R

R interface to TileDB: The Modern Database
https://tiledb-inc.github.io/TileDB-R
Other
103 stars 18 forks source link

More informative error in case of XPtr misuse #740

Closed eddelbuettel closed 4 months ago

eddelbuettel commented 4 months ago

This PR defines a helper class to allow error messages in case of mismatched external pointer tags to be more informative. In the example below, before this PR the message would have been "expected '130' but received '70'" showing the (integer) value of the tag. With the PR this mapped to a char* that can be used in the error message.

> dim <- tiledb_dim("dim", c(1L, 100L), 100L, "INT32") # create an object, here a Dimension
> dim                                                  # which has an R-level pretty-print  method
tiledb_dim(name="dim", domain=c(1L,100L), tile=100L, type="INT32") 
> tiledb:::libtiledb_query_submit(dim@ptr)             # pass pointer to low-leve method expecting a pointer
Error: Wrong tag type: expected 'Query' but received 'Dimension'
> 

The tagging of external pointers (in place for quite some time) avoids hard-to-debug and likely catastrophic run-time errors given that the use of SEXP forces type detection to the run-time.