Skip to content

Commit

Permalink
Fix: check and propagate errors in AsyncBackend
Browse files Browse the repository at this point in the history
Closes #35
  • Loading branch information
mihaiconstantin committed May 7, 2023
1 parent cd6c031 commit 0b7276d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
13 changes: 11 additions & 2 deletions R/AsyncBackend.R
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,17 @@ AsyncBackend <- R6::R6Class("AsyncBackend",

# Set the output based on the session read.
.set_output = function() {
# Store the relevant results from the output.
private$.output <- private$.cluster$read()$result
# Get all session output.
output <- private$.cluster$read()

# If an error ocurred in the session.
if (!is.null(output$error)) {
# Throw error in the main session.
Exception$async_task_error(output$error)
}

# Otherwise, store the relevant results from the output.
private$.output <- output$result
},

# Get the current task state (i.e., what is happening in the session).
Expand Down
7 changes: 7 additions & 0 deletions R/Exception.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#' \item{\code{Exception$async_task_not_started()}}{Exception for reading results while an asynchronous task has not yet started.}
#' \item{\code{Exception$async_task_running()}}{Exception for reading results while an asynchronous task is running.}
#' \item{\code{Exception$async_task_completed()}}{Exception for reading results while a completed asynchronous task has unread results.}
#' \item{\code{Exception$async_task_error(error)}}{Exception for errors while running an asynchronous task.}
#' \item{\code{Exception$temporary_file_creation_failed()}}{Exception for reading results while an asynchronous task is running.}
#' \item{\code{Exception$type_not_assignable(actual, expected)}}{Exception for when providing incorrect object types.}
#' \item{\code{Exception$unknown_package_option(option)}}{Exception for when requesting unknown package options.}
Expand Down Expand Up @@ -92,6 +93,12 @@ Exception$async_task_completed <- function() {
stop("A task is completed with unread results.", call. = FALSE)
}

# Exception for errors in the session while running an asynchronous task.
Exception$async_task_error <- function(error) {
# Throw the error.
stop(error)
}

# Exception for reading results while an asynchronous task is running.
Exception$temporary_file_creation_failed <- function(path) {
# Construct exception message.
Expand Down
1 change: 1 addition & 0 deletions man/Exception.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0b7276d

Please sign in to comment.