@@ -151,7 +151,10 @@ export abstract class RavenCommand<TResult> {
151151 public async send ( agent : Dispatcher ,
152152 requestOptions : HttpRequestParameters ) : Promise < { response : HttpResponse , bodyStream : Readable } > {
153153
154- const { body, uri, fetcher, ...restOptions } = requestOptions ;
154+ // `dispatcher` is pulled out here so it never leaks into `restOptions`: the
155+ // normal path re-adds it explicitly (see below), while the Bun and workerd
156+ // paths must not carry an undici dispatcher into their fetch init.
157+ const { body, uri, fetcher, dispatcher, ...restOptions } = requestOptions ;
155158
156159 log . info ( `Send command ${ this . constructor . name } to ${ uri } ${ body ? " with body " + body : "" } .` ) ;
157160
@@ -167,8 +170,8 @@ export abstract class RavenCommand<TResult> {
167170 // dispatcher here is meaningless and can confuse the runtime.
168171 optionsToUse = { body : bodyToUse , ...restOptions } as RequestInit ;
169172 } else {
170- if ( requestOptions . dispatcher ) { // support for fiddler
171- agent = requestOptions . dispatcher ;
173+ if ( dispatcher ) { // support for fiddler
174+ agent = dispatcher ;
172175 }
173176 optionsToUse = { body : bodyToUse , ...restOptions , dispatcher : agent } as RequestInit ;
174177 }
@@ -184,13 +187,20 @@ export abstract class RavenCommand<TResult> {
184187 const fetchFn = fetcher ?? fetch ; // support for custom fetcher
185188 const response = await fetchFn ( uri , optionsToUse ) ;
186189
187- const effectiveStream : Stream =
188- response . body
189- ? Readable . fromWeb ( response . body )
190- : new Stream ( ) ;
190+ // `Readable.fromWeb` / `new Stream()` / `.pipe` are all `node:stream` APIs,
191+ // so an incomplete edge polyfill (Nitro/unenv) can throw here just like
192+ // `new PassThrough()` above. Guard them so the actionable error is raised.
193+ try {
194+ const effectiveStream : Stream =
195+ response . body
196+ ? Readable . fromWeb ( response . body )
197+ : new Stream ( ) ;
191198
192- effectiveStream
193- . pipe ( passthrough ) ;
199+ effectiveStream
200+ . pipe ( passthrough ) ;
201+ } catch ( err ) {
202+ throw RavenCommand . _maybeNodeStreamUnavailableError ( err as Error ) ;
203+ }
194204
195205 return {
196206 response,
0 commit comments