Skip to content

Commit b86c4c7

Browse files
authored
Ensure warning level 0 (#8)
* Add a warning level fix * Block release * Ensure value is present
1 parent 8a41cb8 commit b86c4c7

File tree

5 files changed

+33
-14
lines changed

5 files changed

+33
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
.Ruserdata
55
.DS_Store
66
inst/doc
7+
CRAN-RELEASE

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: errorist
22
Title: Automatically Search Errors or Warnings
3-
Version: 0.0.3
3+
Version: 0.0.3.9000
44
Authors@R: c(
55
person("James", "Balamuta",
66
email = "[email protected]",

NEWS.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
# errorist 0.0.3.9000
2+
3+
## Fixes
4+
5+
- Ensured the `last.warning` object was created by setting `options('warn' = 0)`,
6+
which is the default value. Upon unload, the warning level is restored to
7+
the old value.
8+
19
# errorist 0.0.3
210

3-
## Bug Fix
11+
## Fixes
412

513
- Address an erroneous unit test that was comparing functions within namespaces
614
instead of environments.

R/handlers.R

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# Package Environment
2-
.errorist_env = new.env()
3-
41
#' Enable or Disable Errorist's Automatic Search
52
#'
63
#' Activates or disengages the automatic look up of error or warning codes in
@@ -156,6 +153,12 @@ enable_warning_shim = function(warning_search_func =
156153
# No warning messages yet (we hope!)
157154
.errorist_env$captured_last_search_warning = NA
158155

156+
# Restore to default setting to ensure `last.warning` is created.
157+
warn_level = getOption("warn", 0)
158+
if (warn_level != 0) {
159+
options("warn" = 0)
160+
}
161+
159162
# Automatically call the warning_handler after each R function is run
160163
handler = addTaskCallback(warning_handler(warning_search_func),
161164
name = "ErroristWarningHandler")
@@ -168,6 +171,9 @@ disable_warning_shim = function() {
168171
# Reset the warning
169172
.errorist_env$captured_last_search_warning = NULL
170173

174+
# Restore original warning level
175+
options("warn" = .errorist_env$warn_level)
176+
171177
# Remove handler
172178
removed_handler = removeTaskCallback("ErroristWarningHandler")
173179
}
@@ -197,9 +203,6 @@ enable_error_shim = function(error_search_func =
197203
# Remove the shim if it exists...
198204
disable_error_shim()
199205

200-
# Save present options
201-
.errorist_env$op = options()
202-
203206
# Errorist
204207
op.errorist = list(error = error_search_func)
205208

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

218-
} else if ("error" %in% names(.errorist_env$op)) {
217+
# Restore options
218+
if ("error" %in% names(.errorist_env$op)) {
219219
options(.errorist_env$op)
220220
} else {
221221
# Ensure error is nullified.
222222
options(error = NULL)
223223
}
224224

225-
.errorist_env$op = NULL
226225
}

R/zzz.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1+
# Package Environment
2+
.errorist_env = new.env()
3+
.errorist_env$warn_level = 0
4+
5+
# Retrieve settings on load
6+
setup_errorist_environment = function() {
7+
.errorist_env$op = options()
8+
.errorist_env$warn_level = getOption("warn", 0)
9+
}
10+
111
.onAttach = function(libname, pkgname) {
212

313
autoload_config = getOption("errorist.autoload", TRUE)
14+
setup_errorist_environment()
415

516
if(!is.logical(autoload_config)) {
617

0 commit comments

Comments
 (0)