@@ -102,6 +102,8 @@ setMethod("scriptSavepoint", "Script", function(x) {
102
102
# ' @param is_file The default guesses whether a file or string was
103
103
# ' used in the `script` argument, but you can override the heuristics
104
104
# ' by specifying `TRUE` for a file, and `FALSE` for a string.
105
+ # ' @param encoding The encoding the script file is saved as on your
106
+ # ' machine. Defaults to UTF-8.
105
107
# ' @param ... Additional options, such as `dry_run = TRUE` passed on
106
108
# ' to the API
107
109
# '
@@ -131,14 +133,20 @@ setMethod("scriptSavepoint", "Script", function(x) {
131
133
# ' }
132
134
# ' @export
133
135
# ' @seealso [`automation-undo`] & [`script-catalog`]
134
- runCrunchAutomation <- function (dataset , script , is_file = string_is_file_like(script ), ... ) {
136
+ runCrunchAutomation <- function (
137
+ dataset ,
138
+ script ,
139
+ is_file = string_is_file_like(script ),
140
+ encoding = " UTF-8" ,
141
+ ...
142
+ ) {
135
143
reset_automation_error_env()
136
144
stopifnot(is.dataset(dataset ))
137
145
stopifnot(is.character(script ))
138
146
139
147
if (is_file ) {
140
148
automation_error_env $ file <- script
141
- script <- readLines(script , encoding = " UTF-8 " , warn = FALSE )
149
+ script <- readLines(script , encoding = encoding , warn = FALSE )
142
150
} else {
143
151
automation_error_env $ file <- NULL
144
152
}
@@ -207,7 +215,7 @@ crunchAutomationErrorHandler <- function(response) {
207
215
msg <- http_status(response )$ message
208
216
automation_messages <- try(content(response )$ resolution , silent = TRUE )
209
217
210
- if (! is.error(automation_messages )) {
218
+ if (! is.error(automation_messages ) && ! is.null( automation_messages ) ) {
211
219
# dig into the response to get the script as we sent it to the server
212
220
request_body <- fromJSON(rawToChar(response $ request $ options $ postfields ))
213
221
automation_error_env $ script <- request_body $ body $ body
@@ -244,6 +252,13 @@ crunchAutomationErrorHandler <- function(response) {
244
252
}
245
253
246
254
msg <- paste(" Crunch Automation Error\n " , error_items , more_info_text , sep = " " )
255
+ } else {
256
+ # could also have information in message property
257
+ # try to use it if it's a character string
258
+ other_msg <- try(content(response )[[" message" ]], silent = TRUE ) # nocov
259
+ if (is.character(other_msg )) { # nocov
260
+ msg <- paste0(msg , " - " , paste0(other_msg , collapse = " \n " )) # nocov
261
+ }
247
262
}
248
263
halt(msg )
249
264
}
0 commit comments