abort_internal_error inside @async

Abierto
#85 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
45/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Tranquilo
Stack tecnológico
r

Línea de trabajo

Start by reproducing the interaction between abort_internal_error() and @async, then inspect how errors propagate out of mirai and how @then handlers are selected. Done means an endpoint using both features propagates the intended error and status without requiring the tryCatch workaround shown in the issue.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

I like both features: abort_internal_error() provides a more human readable error message and return status, and @async can be dead-simple. However, using both does not work due to how errors propagate out of mirai (a known property).

A workaround is to wrap most/all of the async'd endpoint in tryCatch, and return a non-error with enough details, and @then abort with the error message. For example, incomplete code:

#* @get /something
#* async
function() {
  tryCatch({
    stop("my error")
    list(good = TRUE, res = mtcars[1:3,])
  }, error = function(err) {
    list(good = FALSE, err = conditionMessage(err))
  })
}
#* @then
function(response) {
  if (!response$body$good) {
    plumber2::abort_internal_error(response$body$err)
  }
  response$body$res
}

I think if an error is to be propagated, then any @then (if defined) would be overridden with a method that propagates the error as intended. Thoughts?

Lenguaje dominante
R
Estrellas
119
Forks
17
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de posit-dev/plumber2

Todos los issues de posit-dev/plumber2

Issues similares

Más issues de R

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.