1+ const { Readable } = require ( "node:stream" ) ;
2+
13const mime = require ( "mime-types" ) ;
24const { validate } = require ( "schema-utils" ) ;
35
@@ -639,8 +641,39 @@ function honoWrapper(compiler, options = {}, usePlugin = false) {
639641 * @param {import("fs").ReadStream } stream readable stream
640642 */
641643 res . stream = ( stream ) => {
642- if ( options . writeToDisk === true && options . debug ) {
643- console . error ( stream ) ;
644+ if ( options . debug ) {
645+ const patchController = ( ) => {
646+ // @ts -expect-error for debug
647+ console . warn ( "[DEBUG] !!!" , req . getURL ( ) ) ;
648+
649+ const originalEmit = Readable . prototype . emit ;
650+ const originalDestroy = Readable . prototype . destroy ;
651+
652+ // @ts -expect-error for debug
653+ Readable . prototype . emit = function ( event , ...args ) {
654+ if ( [ "close" , "error" , "end" ] . includes ( event ) ) {
655+ console . warn (
656+ // @ts -expect-error for debug
657+ `[DEBUG] (${ req . getURL ( ) } ) ${ this . constructor . name } emit: "${ event } "` ,
658+ ) ;
659+ }
660+ return originalEmit . apply ( this , [ event , ...args ] ) ;
661+ } ;
662+
663+ // @ts -expect-error for debug
664+ Readable . prototype . destroy = function ( err ) {
665+ console . warn (
666+ // @ts -expect-error for debug
667+ `[DEBUG] (${ req . getURL ( ) } ) ${ this . constructor . name } .destroy() call!` ,
668+ ) ;
669+ if ( err ) {
670+ console . error ( "error message:" , err . message , err . stack ) ;
671+ }
672+ return originalDestroy . call ( this , err ) ;
673+ } ;
674+ } ;
675+
676+ patchController ( ) ;
644677 }
645678
646679 let isResolved = false ;
@@ -649,10 +682,6 @@ function honoWrapper(compiler, options = {}, usePlugin = false) {
649682 * @param {Error= } err err
650683 */
651684 const onEvent = ( err ) => {
652- if ( options . writeToDisk === true && options . debug ) {
653- console . error ( "onEvent" , err ) ;
654- }
655-
656685 if ( isResolved ) return ;
657686 isResolved = true ;
658687
@@ -669,10 +698,6 @@ function honoWrapper(compiler, options = {}, usePlugin = false) {
669698 body = stream ;
670699 isFinished = true ;
671700
672- if ( options . writeToDisk === true && options . debug ) {
673- console . error ( "resolve" , isFinished ) ;
674- }
675-
676701 resolve ( ) ;
677702 } ;
678703
@@ -729,10 +754,6 @@ function honoWrapper(compiler, options = {}, usePlugin = false) {
729754 } ,
730755 ) ;
731756 } catch ( err ) {
732- if ( options . writeToDisk === true && options . debug ) {
733- console . error ( "catch" , err ) ;
734- }
735-
736757 if ( options ?. forwardError ) {
737758 await next ( ) ;
738759
@@ -744,18 +765,10 @@ function honoWrapper(compiler, options = {}, usePlugin = false) {
744765 return context . json ( { message : /** @type {Error } */ ( err ) . message } ) ;
745766 }
746767
747- if ( options . writeToDisk === true && options . debug ) {
748- console . error ( "body" , body ) ;
749- }
750-
751768 if ( typeof body !== "undefined" ) {
752769 return context . body ( body , status ) ;
753770 }
754771
755- if ( options . writeToDisk === true && options . debug ) {
756- console . error ( "next" ) ;
757- }
758-
759772 await next ( ) ;
760773 }
761774
0 commit comments