@@ -639,8 +639,28 @@ function honoWrapper(compiler, options = {}, usePlugin = false) {
639639 * @param {import("fs").ReadStream } stream readable stream
640640 */
641641 res . stream = ( stream ) => {
642- if ( options . writeToDisk === true && options . debug ) {
643- console . error ( stream ) ;
642+ if ( options . debug ) {
643+ // @ts -expect-error for debug
644+ const patchController = ( ControllerClass ) => {
645+ const originalClose = ControllerClass . prototype . close ;
646+ const originalError = ControllerClass . prototype . error ;
647+
648+ // @ts -expect-error for debug
649+ ControllerClass . prototype . close = function ( ...args ) {
650+ console . warn ( "Close:" ) ;
651+ console . trace ( ) ;
652+ return originalClose . apply ( this , args ) ;
653+ } ;
654+
655+ // @ts -expect-error for debug
656+ ControllerClass . prototype . error = function ( ...args ) {
657+ console . warn ( "Error:" , args [ 0 ] ) ;
658+ console . trace ( ) ;
659+ return originalError . apply ( this , args ) ;
660+ } ;
661+ } ;
662+
663+ patchController ( stream ) ;
644664 }
645665
646666 let isResolved = false ;
@@ -649,10 +669,6 @@ function honoWrapper(compiler, options = {}, usePlugin = false) {
649669 * @param {Error= } err err
650670 */
651671 const onEvent = ( err ) => {
652- if ( options . writeToDisk === true && options . debug ) {
653- console . error ( "onEvent" , err ) ;
654- }
655-
656672 if ( isResolved ) return ;
657673 isResolved = true ;
658674
@@ -669,10 +685,6 @@ function honoWrapper(compiler, options = {}, usePlugin = false) {
669685 body = stream ;
670686 isFinished = true ;
671687
672- if ( options . writeToDisk === true && options . debug ) {
673- console . error ( "resolve" , isFinished ) ;
674- }
675-
676688 resolve ( ) ;
677689 } ;
678690
@@ -729,10 +741,6 @@ function honoWrapper(compiler, options = {}, usePlugin = false) {
729741 } ,
730742 ) ;
731743 } catch ( err ) {
732- if ( options . writeToDisk === true && options . debug ) {
733- console . error ( "catch" , err ) ;
734- }
735-
736744 if ( options ?. forwardError ) {
737745 await next ( ) ;
738746
@@ -744,18 +752,10 @@ function honoWrapper(compiler, options = {}, usePlugin = false) {
744752 return context . json ( { message : /** @type {Error } */ ( err ) . message } ) ;
745753 }
746754
747- if ( options . writeToDisk === true && options . debug ) {
748- console . error ( "body" , body ) ;
749- }
750-
751755 if ( typeof body !== "undefined" ) {
752756 return context . body ( body , status ) ;
753757 }
754758
755- if ( options . writeToDisk === true && options . debug ) {
756- console . error ( "next" ) ;
757- }
758-
759759 await next ( ) ;
760760 }
761761
0 commit comments