Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta Adatta ai principianti
#25,481 1 commento 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@s1gr1d ci sta già lavorando.

Dal 19/10/2026.

  • #25482 di @itisrmk — chiusa senza merge
  • #25527 di @s1gr1d — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
88/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript, node.js, typescript

Direzione di ricerca

Inizia da getRouteMetadata in packages/server-utils/src/integrations/hapi/hapi-utils.ts e dal percorso di wrapRouteHandler mostrato nello stack trace, quindi esegui la riproduzione dell'issue con node --import ./instrument.mjs server.mjs. Verifica come il handler avvolto riceve la richiesta risolta e come il suo metodo viene usato per il nome dello span e per http.request.method. Il lavoro è completo quando le route configurate tramite array non lanciano più errori, sia /single sia /multi restituiscono 200 con il ciclo di vita statico del trace e i metadati del metodo rimangono corretti.

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

Descrizione

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

Lingua principale
TypeScript
Stelle
8.8k
Fork
1.9k
Merge medio
1g 12h
PR unite (30g)
598

Preparare l'ambiente

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 getsentry/sentry-javascript

Tutte le issue di getsentry/sentry-javascript

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.