safe_untrace() silently (because of the try()) fails, if given a function as argument:
# as in stop_mocking()
safe_untrace(curl::form_file)
This can not work since:
what == curl::form_file, a function
get(what, env) - requires a character first argument
It silently fails because of the try(, silent = TRUE).
Also, it could not work with safe_untrace("curl::form_file") since get() does not understand scoped function names.
Instead, it should be called like:
>safe_untrace('form_file', where = getNamespace('curl'))
Untracing function "form_file" in package "namespace:curl"
[1] "form_file"
It is partially responsible for #66 .
For reference:
safe_untrace <- function(what, where = sys.frame()) {
# If you attempt to untrace a function (1) that isn't exported from
# whatever namespace it lives in and (2) that isn't currently traced,
# it errors. This prevents that so that it's always safe to call `untrace`
# untrace() and get() handle enviroments differently
if (is.environment(where)) {
env <- where
} else {
env <- environment(where)
}
if (inherits(try(get(what, env), silent = TRUE), "functionWithTrace")) {
quietly(untrace(what, where = where))
}
}
safe_untrace()
silently (because of the try()) fails, if given a function as argument:This can not work since:
get(what, env)
- requires a character first argument It silently fails because of thetry(, silent = TRUE)
.Also, it could not work with
safe_untrace("curl::form_file")
since get() does not understand scoped function names. Instead, it should be called like:It is partially responsible for #66 .
For reference: