diff options
author | 2023-01-27 00:21:04 -0800 | |
---|---|---|
committer | 2023-01-27 00:21:04 -0800 | |
commit | 1da7f5fe5defb1294ffe4eb646c71b852b044d72 (patch) | |
tree | 33b011067f2938b4ba1061538e438a557c0eaf86 | |
parent | 655c19b07ca4c551eeb88eae9e2fc1db802af362 (diff) | |
download | bun-1da7f5fe5defb1294ffe4eb646c71b852b044d72.tar.gz bun-1da7f5fe5defb1294ffe4eb646c71b852b044d72.tar.zst bun-1da7f5fe5defb1294ffe4eb646c71b852b044d72.zip |
[`bun --hot`] Report exceptions in reloaded modules
-rw-r--r-- | src/bun_js.zig | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/src/bun_js.zig b/src/bun_js.zig index 564a6a6c9..2b3e514e6 100644 --- a/src/bun_js.zig +++ b/src/bun_js.zig @@ -175,9 +175,34 @@ pub const Run = struct { } { - while (vm.eventLoop().tasks.count > 0 or vm.active_tasks > 0 or vm.uws_event_loop.?.active > 0) { - vm.tick(); - vm.eventLoop().autoTickActive(); + if (this.vm.isWatcherEnabled()) { + var prev_promise = this.vm.pending_internal_promise; + if (prev_promise.status(vm.global.vm()) == .Rejected) { + vm.onUnhandledError(this.vm.global, this.vm.pending_internal_promise.result(vm.global.vm())); + } + + while (vm.eventLoop().tasks.count > 0 or vm.active_tasks > 0 or vm.uws_event_loop.?.active > 0) { + vm.tick(); + + // Report exceptions in hot-reloaded modules + if (this.vm.pending_internal_promise.status(vm.global.vm()) == .Rejected and prev_promise != this.vm.pending_internal_promise) { + prev_promise = this.vm.pending_internal_promise; + vm.onUnhandledError(this.vm.global, this.vm.pending_internal_promise.result(vm.global.vm())); + continue; + } + + vm.eventLoop().autoTickActive(); + } + + if (this.vm.pending_internal_promise.status(vm.global.vm()) == .Rejected and prev_promise != this.vm.pending_internal_promise) { + prev_promise = this.vm.pending_internal_promise; + vm.onUnhandledError(this.vm.global, this.vm.pending_internal_promise.result(vm.global.vm())); + } + } else { + while (vm.eventLoop().tasks.count > 0 or vm.active_tasks > 0 or vm.uws_event_loop.?.active > 0) { + vm.tick(); + vm.eventLoop().autoTickActive(); + } } if (vm.log.msgs.items.len > 0) { |