From af240bff581be1ad63c7ed15fa182f23a3809fa2 Mon Sep 17 00:00:00 2001 From: mkoohafkan Date: Mon, 5 Aug 2019 15:55:06 -0700 Subject: [PATCH] cleaner error when unloading fails --- R/connect.r | 10 ++++++---- R/zzz.r | 10 ++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/R/connect.r b/R/connect.r index e68c127..3541e01 100644 --- a/R/connect.r +++ b/R/connect.r @@ -192,10 +192,12 @@ hql_unload = function() { if (hql_is_loaded()) { dllpath = normalizePath(file.path(hql.paths$install, hql.paths$dll), mustWork = TRUE) - lapply(dllpath, dyn.unload) - if (hql_is_loaded()) { - stop("HDFql DLLs could not be unloaded.") - } + for (dll in dllpath) { + dyn.unload(dll) + if (dll %in% sapply(getLoadedDLLs(), function(x) normalizePath(x[["path"]], mustWork = FALSE))) { + stop("Error unloading HDFql shared library object ", dll) + } + } rm(list = "wrapper", envir = hql) } invisible(NULL) diff --git a/R/zzz.r b/R/zzz.r index 7dd9785..eb1550c 100644 --- a/R/zzz.r +++ b/R/zzz.r @@ -15,9 +15,15 @@ } .onUnload = function(libpath) { - hql_unload() + tryCatch(hql_unload(), + error = function(e) { + warning(packageName(), " could not be unloaded cleanly\n", e$message) + }) } .onDetach = function(libpath) { - hql_unload() + tryCatch(hql_unload(), + error = function(e) { + warning(packageName(), " could not be unloaded cleanly\n", e$message) + }) }