Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

Hapi: `route.method.toUpperCase is not a function` for routes registered with an array of methods

未關閉 適合新手
#25,481 1 則留言 0 個 reaction 已指派 1 人 在 GitHub 檢視

維護者通常 1 天內回覆

@s1gr1d 已經在處理了。

開始於 2026年10月19日。

  • #25482 來自 @itisrmk —— 已關閉,未合併
  • #25527 來自 @s1gr1d —— 未關閉

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
88/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍

研究方向

先查看 packages/server-utils/src/integrations/hapi/hapi-utils.ts 中的 getRouteMetadata,以及 stack trace 中顯示的 wrapRouteHandler 路徑,然後執行 issue 中的 node --import ./instrument.mjs server.mjs 重現方式。檢查被包裝的 handler 如何接收已解析的請求,以及請求方法如何用於 span 名稱和 http.request.method。完成的標準是:透過 array 設定的路由不再拋出例外,/single 和 /multi 在靜態 trace 生命週期下都回傳 200,且方法 metadata 維持正確。

由索引模型根據 Issue 內容生成。

描述

Bug Hapi Waiting for: Product Owner
Is there an existing issue for this?
How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node - hapi

SDK Version

11.5.0; also present in 11.8.0

Framework Version

No response

Link to Sentry event

No response

Reproduction Example/SDK Setup

No response

Steps to Reproduce

instrument.mjs:

import * as Sentry from '@sentry/node';
Sentry.init({
  dsn: 'https://[email protected]/1',
  tracesSampleRate: 1,
  traceLifecycle: 'static',
});

server.mjs:

import Hapi from '@hapi/hapi';
const server = Hapi.server({ port: 0 });
server.route({ method: ['GET', 'POST'], path: '/multi', handler: () => 'ok' });
server.route({ method: 'GET', path: '/single', handler: () => 'ok' });
await server.start();
for (const path of ['/single', '/multi']) {
  const res = await fetch(server.info.uri + path);
  console.log(path, res.status);
}
await server.stop();

Run node --import ./instrument.mjs server.mjs

Expected Result

Both requests return 200.

Actual Result

/single returns 200; /multi returns 500:

TypeError: route.method.toUpperCase is not a function
    at getRouteMetadata (@sentry/server-utils/src/integrations/hapi/hapi-utils.ts:132:73)
    at <anonymous> (@sentry/server-utils/src/integrations/hapi/hapi-utils.ts:202:24)
    at exports.Manager.execute (@hapi/hapi/lib/toolkit.js:57:29)
    at internals.handler (@hapi/hapi/lib/handler.js:46:48)
    ...

With the default traceLifecycle ('stream'), both return 200.

Additional Context

Hapi accepts method as a string or an array of strings. wrapRouteHandler passes the route config given to server.route() to getRouteMetadata. For non-streamed spans, that builds the span name as `${route.method.toUpperCase()} ${route.path}`, which assumes a string. The streamed-span branch only uses route.path, which is why the default lifecycle is unaffected. Either way, the array also ends up in the http.request.method attribute.

A possible fix: inside the wrapped handler, read the method from the request (request.method, which Hapi has already resolved to one lowercase method) rather than from the route config.

Priority

No response

主要語言
TypeScript
星號
8.8k
分支
1.9k
平均合併
1 天 12 小時
30 天內合併 PR
598

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

getsentry/sentry-javascript 的其他 Issue

查看 getsentry/sentry-javascript 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。