mdneuzerling / lambdr

Run R containers on AWS Lambda
https://lambdr.mdneuzerling.com
Other
131 stars 12 forks source link

Is this the correct way to get the stacktrace of the current error? #1

Closed mdneuzerling closed 3 years ago

mdneuzerling commented 3 years ago

Is this the correct way to get the stacktrace of an error in a tryCatch? Does it leave behind a current_error variable that needs to be cleaned up?

post_lambda_error <- function(e, endpoint) {
  utils::dump.frames("current_error")
  current_traceback <- names(current_error)
  error_list <- list(
    errorMessage = e$message,
    errorType = class(e)[[1]],
    stackTrace = current_traceback
  )
  error_json <- jsonlite::toJSON(error_list, auto_unbox = TRUE)
  httr::POST(
    url = endpoint,
    body = error_json,
    encode = "raw",
    httr::content_type("application/vnd.aws.lambda.error+json")
  )
}