Response cannot be returned because it's being parsed to character
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 68/100
Direzione di ricerca
Start by running the minimal plumber2 app from the report and compare the handlers using response$status, response$set_header(), and a plain response return. Trace the response formatting path that calls as.character(); done means a 302 response with the Location header is returned without an internal server error, including when the handler returns the response object.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
According to the documentation, the response object can be returned:
But when I try to run this minimal plumber app:
library(plumber2)
#* @plumber
function(api) {
api |>
api_logger(
logger_console(),
access_log_format = plumber2::combined_log_format
) |>
api_get("/", function(request, response) {
response$status <- 302L
response$set_header("Location", "echo/hello123")
})
}
#* Echo the parameter that was sent in
#*
#* @get /echo/<msg>
#*
#* @param msg:string The message to echo back.
#*
#* @response 200:{msg:string} A string containing the input message
#*
function(msg) {
msg
}
I get "internal server errors" instead of the redirect to echo/hello123 and can see in the logs the following errors messages:
2026-07-07 13:59:04.411662 - error: Error formatting the response body
2026-07-07 13:59:04.411662 - error: Caused by error in `as.character()`:
2026-07-07 13:59:04.411662 - error: ! cannot coerce type 'closure' to vector of type 'character'
This happens because response$set_header() returns the modified response object instead of NULL. So if I were first set the header and then the status, then everything works as expected (because the assignment returns NULL):
#* @plumber
function(api) {
api |>
api_logger(
logger_console(),
access_log_format = plumber2::combined_log_format
) |>
api_get("/", function(request, response) {
response$set_header("Location", "echo/hello123")
response$status <- 302L # <<<<<<<<<<<< This returns NULL
})
}
I tried to investigate if this is due to modification of set_header() that returning a response object erros but this code still causes the same error:
#* @plumber
function(api) {
api |>
api_logger(
logger_console(),
access_log_format = plumber2::combined_log_format
) |>
api_get("/", function(request, response) {
response # <<<<<<<<<< Returning the plain response object
})
}
- 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
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di posit-dev/plumber2
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
`except` argument in `Plumber2$add_shiny` method is not respectedForse già presa @cgiachalis l’ha presa 139 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 78/100
-
Development RoadmapAperta
Difficoltà 2/5 Meno di un'ora Idoneità per principianti 20/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 52/100
Tutte le issue di posit-dev/plumber2
Issue simili
-
num_ode_rk4_adaptive rejects atol = 0 while accepting rtol = 0 and while num_ode_dopri5 accepts bothApertaarea/ode-pde good first issue help wanted kind/contract severity/4-minor
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Apich-Organization/rssn#383 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
PRL-PRG/r-compile-server#70 · 1 commento ·
-
dependencies docker enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
posit-dev/images-workbench#257 ·
I maintainer di solito rispondono entro 1 giorno
-
dependencies docker enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
posit-dev/images-package-manager#188 ·
I maintainer di solito rispondono entro 1 giorno
-
dependencies docker enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
posit-dev/images-connect#222 ·
I maintainer di solito rispondono entro 1 giorno