abort_internal_error inside @async

Aperta
#85 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
r

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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?

Lingua principale
R
Stelle
119
Fork
17
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di posit-dev/plumber2

Tutte le issue di posit-dev/plumber2

Issue simili

Altre issue su R

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.