Skip to content

Commit

Permalink
auto-compute function_name_for_messages
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl committed Oct 28, 2024
1 parent 8403c10 commit 8f64cf1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
3 changes: 1 addition & 2 deletions apis/r/R/SOMADataFrame.R
Original file line number Diff line number Diff line change
Expand Up @@ -416,14 +416,13 @@ SOMADataFrame <- R6::R6Class(
#' `soma_joinid` domain slot.
#' @return No return value
tiledbsoma_resize_soma_joinid_shape = function(new_shape) {

stopifnot("'new_shape' must be an integer" = rlang::is_integerish(new_shape, n = 1) ||
(bit64::is.integer64(new_shape) && length(new_shape) == 1)
)
# Checking slotwise new shape >= old shape, and <= max_shape, is already done in libtiledbsoma
invisible(
resize_soma_joinid_shape(
self$uri, new_shape, "tiledbsoma_resize_soma_joinid_shape", private$.soma_context))
self$uri, new_shape, .name_of_function(), private$.soma_context))
}

),
Expand Down
4 changes: 2 additions & 2 deletions apis/r/R/SOMANDArrayBase.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ SOMANDArrayBase <- R6::R6Class(
(bit64::is.integer64(new_shape) && length(new_shape) == self$ndim())
)
# Checking slotwise new shape >= old shape, and <= max_shape, is already done in libtiledbsoma
resize(self$uri, new_shape, "resize", private$.soma_context)
resize(self$uri, new_shape, .name_of_function(), private$.soma_context)
},

#' @description Allows the array to have a resizeable shape as described in the
Expand All @@ -125,7 +125,7 @@ SOMANDArrayBase <- R6::R6Class(
(bit64::is.integer64(shape) && length(shape) == self$ndim())
)
# Checking slotwise new shape >= old shape, and <= max_shape, is already done in libtiledbsoma
tiledbsoma_upgrade_shape(self$uri, shape, "tiledbsoma_upgrade_shape", private$.soma_context)
tiledbsoma_upgrade_shape(self$uri, shape, .name_of_function(), private$.soma_context)
}

),
Expand Down
19 changes: 19 additions & 0 deletions apis/r/R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,22 @@ SOMA_ENCODING_VERSION <- "1.1.0"
##' @importFrom spdl setup
##' @useDynLib tiledbsoma, .registration=TRUE
NULL

# This is for internal logging purposes. Context:
# * We have R (and Python) code with function names the user invokes.
# * These call C++ functions which can throw their own error messages.
# * It's crucial that the C++ code "knows" the name of the function
# as typed by the user, not whatever (possibly out-of-date) guess
# the C++ code may have.
.name_of_function <- function() {
# Tricky bits:
# * This might be `obj$foo`
# * The sys.call can return a parse-tree component (typeof = language)
# with the '$', 'obj', and 'foo' -- hence the as.character
# * Even then there can be a second component returned like 'c(1)'
# -- hence the [[1]]
# * Then remove the 'obj$' from 'obj$foo'
name <- as.character(sys.call(sys.parent(n=1)))[[1]]
name <- sub('.*\\$', replacement = '', x = name)
return(name)
}
4 changes: 2 additions & 2 deletions libtiledbsoma/src/soma/soma_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1665,14 +1665,14 @@ void SOMAArray::_set_shape_helper(
// Upgrading an array to install a current domain
if (!_get_current_domain().is_empty()) {
throw TileDBSOMAError(fmt::format(
"{}: array must not already have a shape",
"{}: array must not already have a shape: please upgrade it",
function_name_for_messages));
}
} else {
// Expanding an array's current domain
if (_get_current_domain().is_empty()) {
throw TileDBSOMAError(fmt::format(
"{} array must already have a shape",
"{} array must already have a shape: please upgrade it",
function_name_for_messages));
}
}
Expand Down

0 comments on commit 8f64cf1

Please sign in to comment.