Skip to content

Commit f49d718

Browse files
test: debug
1 parent d754291 commit f49d718

2 files changed

Lines changed: 23 additions & 23 deletions

File tree

src/index.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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

test/middleware.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4641,7 +4641,7 @@ describe.each([
46414641
name,
46424642
framework,
46434643
compiler,
4644-
{ writeToDisk: true },
4644+
{ writeToDisk: true, debug: true },
46454645
);
46464646
});
46474647

0 commit comments

Comments
 (0)