-
Notifications
You must be signed in to change notification settings - Fork 14
Error messages being squelched #34
Description
Hi!
I'm developing an R package that creates a MonetDBLite database of biological sequence data (https://github.com/ropensci/restez). Users can run automated functions for downloading large amounts of sequence data and store it in the database.
Recently, one user encountered the following error:
: Invalid argument
simpleError in gsub("\n", " ", res, fixed = TRUE): Unable to execute statement 'ROLLBACK'.
Server says 'SQLException:sql.trans:2DM30!ROLLBACK: not allowed in auto commit mode'.>
Error in gsub("\n", " ", res, fixed = TRUE) :
input string 1 is invalid UTF-8
The error appears to be due to an unexpected encoding for the incoming character string to gsub. I suspected it was due to foreign language symbols (the user's computer is in French). Initially, I was able to recreate the error on a Windows machine in Swedish. I was then able to fix the gsub error by re-encoding the incoming string for gsub in the monetdb_embedded_query function using iconv (see updated function below). Now when re-running the original user's code (you can recreate the error with this script), I get a message about what is exactly failing (partly in Swedish).
ftruncate: Invalid argument
Error in .local(conn, statement, ...) :
Unable to execute statement 'COMMIT'.
].ver says 'ERROR: HEAPextend: failed to extend for 05\516.theap: GDKmremap() failed ' [#OS: Enheten k‰nner inte igen kommandot.
.... which indicates that we're asking too much of our machine.
If I have diagnosed the problem correctly, could the monetdb_embedded_query function be updated to handle foreign language characters? Below is my updated version of the function, note the addition of iconv lines.
Many thanks,
Dom
monetdb_embedded_query <- function(conn, query, execute=TRUE, resultconvert=TRUE, int64=FALSE) {
print('My function')
if (!inherits(conn, MonetDBLite:::classname)) {
stop("Invalid connection")
}
query <- as.character(query)
if (length(query) != 1) {
stop("Need a single query as parameter.")
}
if (!MonetDBLite:::monetdb_embedded_env$is_started) {
stop("Call monetdb_embedded_startup() first")
}
if (MonetDBLite:::monetdb_embedded_env$started_dir != ":memory:" &&
!dir.exists(file.path(MonetDBLite:::monetdb_embedded_env$started_dir, "bat"))) {
stop("Someone killed all the BATs! Call Brigitte Bardot!")
}
execute <- as.logical(execute)
if (length(execute) != 1) {
stop("Need a single execute flag as parameter.")
}
resultconvert <- as.logical(resultconvert)
if (length(resultconvert) != 1) {
stop("Need a single resultconvert flag as parameter.")
}
int64 <- as.logical(int64)
if (length(resultconvert) != 1) {
stop("Need a single int64 flag as parameter.")
}
if (int64 && !requireNamespace("bit64", quietly = TRUE)) {
stop("Need bit64 package for integer64 support")
}
# make sure the query is terminated
query <- paste(query, "\n;", sep="")
res <- .Call(MonetDBLite:::monetdb_query_R, conn, query, execute, resultconvert, interactive() &&
getOption("monetdb.progress", FALSE), int64)
resp <- list()
if (is.character(res)) { # error
resp$type <- "!" # MSG_MESSAGE
res <- iconv(res, to = 'UTF-8')
resp$message <- gsub("\n", " ", res, fixed=TRUE)
}
if (is.numeric(res)) { # no result set, but successful
resp$type <- 2 # Q_UPDATE
resp$rows <- res
}
if (is.list(res)) {
resp$type <- 1 # Q_TABLE
if ("__prepare" %in% names(attributes(res))) {
resp$type <- Q_PREPARE
resp$prepare = attr(res, "__prepare")
attr(res, "__prepare") <- NULL
}
attr(res, "row.names") <- c(NA_integer_, as.integer(-1 * attr(res, "__rows")))
class(res) <- "data.frame"
names(res) <- gsub("\\", "", names(res), fixed=T)
resp$tuples <- res
}
resp
}