Skip to content

Commit

Permalink
Improves how error is capture, displayed, and returned
Browse files Browse the repository at this point in the history
  • Loading branch information
edgararuiz committed May 2, 2024
1 parent c83da30 commit f366992
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
3 changes: 1 addition & 2 deletions R/app-server.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ app_server <- function(input, output, session) {
error <- ch_r_error()
if (!is.null(error)) {
stopApp()
print(error)
abort("Streaming returned error")
abort(error)
}
})
}
Expand Down
10 changes: 6 additions & 4 deletions R/ch-r.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ ch_r_output <- function() {

ch_r_error <- function() {
out <- NULL
if (!is.null(ch_env$r_session)) {
read_session <- ch_env$r_session$read()
if (!is.null(read_session)) {
out <- read_session$error
err <- ch_env$r_session$read_error()
if (err != "") {
error_marker <- "! {error}"
if(substr(err, 1, nchar(error_marker)) == error_marker) {
err <- substr(err, nchar(error_marker) + 1, nchar(err))
}
out <- err
}
out
}
4 changes: 4 additions & 0 deletions R/chattr.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ chattr <- function(prompt = NULL,
ret <- c(ret, curr_text)
ide_paste_text(curr_text)
}
error <- ch_r_error()
if (!is.null(error)) {
abort(error)
}
} else {
ret <- ch_submit(
defaults = defaults,
Expand Down

0 comments on commit f366992

Please sign in to comment.