Response cannot be returned because it's being parsed to character

オープン
#92 コメント 0 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
68/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
r
領域
api

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

According to the documentation, the response object can be returned:

Image

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
    })
}
主要言語
R
スター
119
フォーク
17
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

posit-dev/plumber2 のほかの issue

posit-dev/plumber2 の issue をすべて見る

似ている issue

R の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。