-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #129 use rlang throughout where useful
- reworked assert_* fxns to use rlang and throw better error messages that allow better trace back - add section to stub_request about error handling - new helper functions in error-handling.R file to help with stub removal upon appropriate error - use withCallingHandlers in the fxns used with stub_request (wi_th, to_return, etc.) to catch and remove stubs upon most errors - modify tests accordingly for above line change
- Loading branch information
Showing
30 changed files
with
308 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,8 @@ Imports: | |
fauxpas, | ||
crul (>= 0.7.0), | ||
base64enc, | ||
rlang | ||
rlang, | ||
cli | ||
Suggests: | ||
testthat, | ||
xml2, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
errors_to_skip_stub_removal <- function() { | ||
mssgs <- c( | ||
"\".data\" is missing", | ||
"must be of class StubbedRequest", | ||
"not registered", | ||
"Unknown" | ||
# , | ||
# "all objects must be error classes" | ||
) | ||
paste0(mssgs, collapse = "|") | ||
} | ||
|
||
stub_removal_message <- c( | ||
"Encountered an error constructing stub", | ||
"Removed stub", | ||
"To see a list of stubs run stub_registry()" | ||
) | ||
|
||
#' Handle stub removal | ||
#' @keywords internal | ||
#' @param .data an object of class `StubbedRequest` required | ||
#' @param code a code block. required | ||
#' @return if no error, the result of running `code`; if an error occurs | ||
#' [withCallingHandlers()] throws a warning and then the stub is removed | ||
handle_stub_removal <- function(.data, code) { | ||
withCallingHandlers({ | ||
force(code) | ||
}, | ||
error = function(cnd) { | ||
if (!grepl(errors_to_skip_stub_removal(), cnd$message)) { | ||
warn(stub_removal_message) | ||
remove_request_stub(.data) | ||
} | ||
}) | ||
} | ||
|
||
# FIXME: add envir handling so that error message says the exported user fxn that the error occurred in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.