Skip to content

Commit

Permalink
Ensure warning level 0 (#8)
Browse files Browse the repository at this point in the history
* Add a warning level fix

* Block release

* Ensure value is present
  • Loading branch information
coatless committed Feb 21, 2020
1 parent 8a41cb8 commit b86c4c7
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
.Ruserdata
.DS_Store
inst/doc
CRAN-RELEASE
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: errorist
Title: Automatically Search Errors or Warnings
Version: 0.0.3
Version: 0.0.3.9000
Authors@R: c(
person("James", "Balamuta",
email = "balamut2@illinois.edu",
Expand Down
10 changes: 9 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# errorist 0.0.3.9000

## Fixes

- Ensured the `last.warning` object was created by setting `options('warn' = 0)`,
which is the default value. Upon unload, the warning level is restored to
the old value.

# errorist 0.0.3

## Bug Fix
## Fixes

- Address an erroneous unit test that was comparing functions within namespaces
instead of environments.
Expand Down
23 changes: 11 additions & 12 deletions R/handlers.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Package Environment
.errorist_env = new.env()

#' Enable or Disable Errorist's Automatic Search
#'
#' Activates or disengages the automatic look up of error or warning codes in
Expand Down Expand Up @@ -156,6 +153,12 @@ enable_warning_shim = function(warning_search_func =
# No warning messages yet (we hope!)
.errorist_env$captured_last_search_warning = NA

# Restore to default setting to ensure `last.warning` is created.
warn_level = getOption("warn", 0)
if (warn_level != 0) {
options("warn" = 0)
}

# Automatically call the warning_handler after each R function is run
handler = addTaskCallback(warning_handler(warning_search_func),
name = "ErroristWarningHandler")
Expand All @@ -168,6 +171,9 @@ disable_warning_shim = function() {
# Reset the warning
.errorist_env$captured_last_search_warning = NULL

# Restore original warning level
options("warn" = .errorist_env$warn_level)

# Remove handler
removed_handler = removeTaskCallback("ErroristWarningHandler")
}
Expand Down Expand Up @@ -197,9 +203,6 @@ enable_error_shim = function(error_search_func =
# Remove the shim if it exists...
disable_error_shim()

# Save present options
.errorist_env$op = options()

# Errorist
op.errorist = list(error = error_search_func)

Expand All @@ -210,17 +213,13 @@ enable_error_shim = function(error_search_func =
#' @rdname shims
#' @export
disable_error_shim = function() {
# Restore options
if (exists("op", envir = .errorist_env) &&
is.null(.errorist_env$op)) {
# Empty if condition...

} else if ("error" %in% names(.errorist_env$op)) {
# Restore options
if ("error" %in% names(.errorist_env$op)) {
options(.errorist_env$op)
} else {
# Ensure error is nullified.
options(error = NULL)
}

.errorist_env$op = NULL
}
11 changes: 11 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# Package Environment
.errorist_env = new.env()
.errorist_env$warn_level = 0

# Retrieve settings on load
setup_errorist_environment = function() {
.errorist_env$op = options()
.errorist_env$warn_level = getOption("warn", 0)
}

.onAttach = function(libname, pkgname) {

autoload_config = getOption("errorist.autoload", TRUE)
setup_errorist_environment()

if(!is.logical(autoload_config)) {

Expand Down

0 comments on commit b86c4c7

Please sign in to comment.