@@ -6,7 +6,15 @@ report_error <- function(response) {
6
6
invisible (response )
7
7
} else {
8
8
call <- sys.call(- 1 )
9
- stop(create_condition(response , " error" , call = call ))
9
+
10
+ cond <- create_condition(response , " error" , call = call )
11
+
12
+ # Sometimes the message from create_condition can be very long, but it is
13
+ # necessary to show the whole thing so that the user can understand it.
14
+ old_options <- options(warning.length = nchar(cond $ message ))
15
+ on.exit(options(old_options ))
16
+
17
+ stop(cond )
10
18
}
11
19
}
12
20
@@ -18,24 +26,34 @@ create_condition <- function(response,
18
26
19
27
class <- match.arg(class )
20
28
21
- cont <- content(response )
29
+ cont <- content(response , as = " text" )
30
+
31
+ message <- NULL
32
+ status <- NULL
22
33
23
- if (is.character(cont )) {
24
- # In rare cases the error content is just a string. This can happen, for
25
- # example, when there is a problem loading execute_script.js.
26
- # https://github.com/rstudio/shinytest/issues/165
34
+ if (jsonlite :: validate(cont )) {
35
+ try({
36
+ # This can error if `cont` doesn't include the fields we want.
37
+ json <- fromJSON(
38
+ cont [[" value" ]][[" message" ]],
39
+ simplifyVector = FALSE
40
+ )
41
+ message <- json [[" errorMessage" ]] %|| % " WebDriver error"
42
+ status <- cont $ status
43
+ })
44
+ }
45
+
46
+ # We can end up in this block if:
47
+ # * The error content is just a string, or raw HTML. This can happen, for
48
+ # example, when there is a problem loading execute_script.js.
49
+ # https://github.com/rstudio/shinytest/issues/165
50
+ # https://github.com/rstudio/shinytest/issues/190
51
+ # * The `cont` object was JSON, but did not include the needed fields.
52
+ if (is.null(status )) {
27
53
message <- cont
28
54
# Need to manually set status code for UnknownError. From:
29
55
# https://github.com/detro/ghostdriver/blob/873c9d6/src/errors.js#L135
30
56
status <- 13L
31
-
32
- } else {
33
- json <- fromJSON(
34
- cont [[" value" ]][[" message" ]],
35
- simplifyVector = FALSE
36
- )
37
- message <- json [[" errorMessage" ]] %|| % " WebDriver error"
38
- status <- cont $ status
39
57
}
40
58
41
59
0 commit comments