DispatchOptions.upgrade accepts boolean in types but runtime rejects it
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 76/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Tranquilla
- Stack tecnologico
- javascript, typescript
Direzione di ricerca
Inizia da types/dispatcher.d.ts:116-117 e lib/core/request.js:134-136, quindi segui il percorso di errore in lib/dispatcher/dispatcher-base.js:172-180. Verifica le convenzioni esistenti per i test di tipo e di runtime relativi a DispatchOptions e alla validazione delle request. Il lavoro è completato quando il contratto pubblico di upgrade corrisponde al comportamento a runtime, gli upgrade string validi continuano a essere accettati e i valori non validi sono coperti tramite il percorso di errore dell’handler.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
DispatchOptions.upgrade currently accepts boolean in the public TypeScript type, but the runtime request validator rejects any truthy non-string value with InvalidArgumentError: upgrade must be a string. A TypeScript-valid call such as client.dispatch({ path: '/', method: 'GET', upgrade: true }, handler) therefore fails before any connector/network dispatch.
Code path
Producer / validator / feedback anchors:
types/dispatcher.d.ts:116-117:upgrade?: boolean | string | null;lib/core/request.js:134-136: truthyupgradevalues are rejected unlesstypeof upgrade === 'string'.lib/dispatcher/dispatcher-base.js:172-180: the validator failure is surfaced throughhandler.onResponseError(null, err)anddispatch()returnsfalsewhen the handler has an error hook.
Steps to reproduce
Validation level: dynamic reproduction plus source-control-flow validation.
const { Client } = require('undici')
const client = new Client('http://127.0.0.1:9', {
connect () {
throw new Error('connector should not be reached when option validation fails')
},
})
const handler = {
onRequestStart () {},
onResponseStart () {},
onResponseData () {},
onResponseEnd () {},
onResponseError (_controller, err) {
console.log(`handler.error.name=${err.name}`)
console.log(`handler.error.message=${err.message}`)
},
}
console.log(client.dispatch({ path: '/', method: 'GET', upgrade: true }, handler))
Observed output from the local repro:
handler.error.name=InvalidArgumentError
handler.error.message=upgrade must be a string
dispatch_return=false
Expected behavior
The public type and runtime validator should agree on the upgrade option contract. Either boolean should be rejected by TypeScript, or true should be normalized to a well-defined upgrade token.
Actual behavior
The TypeScript surface permits upgrade: true, but runtime rejects it before dispatch and reports upgrade must be a string.
Existing coverage
I searched current open/closed issues and PRs for upgrade must be a string, DispatchOptions upgrade boolean, and related types/dispatcher.d.ts upgrade terms. I did not find exact coverage. Nearby upgrade/WebSocket issues and PRs appear to cover protocol behavior, not this type/runtime option drift.
Suggested fix
The lower-risk fix is to narrow DispatchOptions.upgrade to string | null, matching the current runtime validator. If boolean support is intended, the runtime should define and test what true means.
Suggested tests
- Add a type-level negative assertion for
upgrade: trueonDispatchOptionsif narrowing the type. - Keep or add a runtime test that
upgrade: 'websocket'remains accepted. - Keep invalid non-string runtime values flowing to
onResponseError.
Submitted with Codex.
- Lingua principale
- JavaScript
- Stelle
- 7.7k
- Fork
- 931
- Merge medio
- 3g 1h
- PR unite (30g)
- 92
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
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 nodejs/undici
-
Un-experimental DecompressInterceptorForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertaenhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
I maintainer di solito rispondono entro 1 giorno
-
MockPool/MockClient `cleanMocks()` doesn't clear the interceptors that Node.js global fetch usesForse già presa @Anoesj l’ha presa 3 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
document: Broken link for CacheHandler.CacheOptionsForse già presa @MFA-G l’ha presa 3 giorni fa. Aperta
Difficoltà 2/5 Mezza giornata Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
Fix `test:typescript` script for Windows compatibilityForse già presa @shivarm l’ha presa 17 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
I maintainer di solito rispondono entro 1 giorno
-
Socks5ProxyAgent: SOCKS5 handshake/auth timeout leaks the underlying socketForse già presa @drewmt l’ha presa 58 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di nodejs/undici
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
bigskysoftware/htmx#4147 ·
I maintainer di solito rispondono entro 5 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
vshymanskyy/StandWithUkraine#316 ·
-
bug/1-unconfirmed kind/bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 74/100
521xueweihan/HelloGitHub#4010 · 2 commenti ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100