Skip to content

Commit

Permalink
Add unhandeled rejections again
Browse files Browse the repository at this point in the history
  • Loading branch information
benStre committed Feb 12, 2024
1 parent 149820d commit 3cb3a9b
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@ import { Path } from "./utils/path.ts";
import { communicationHub } from "./network/communication-hub.ts";
import { LocalLoopbackInterface } from "./network/communication-interfaces/local-loopback-interface.ts";
import { Crypto } from "./runtime/crypto.ts";
import { sendReport } from "./utils/error-reporting.ts";


if (client_type == "deno") {
globalThis.addEventListener("unhandledrejection", (e: PromiseRejectionEvent) => {
const error = e.reason instanceof Error ?
{ message: e.reason.message, stack: e.reason.stack } :
e.reason ?? e;
console.error("Uncaught promise:", e.promise, e.reason);

if (error?.message?.includes("BadResource") || error?.includes?.("BadResource")) {
e.preventDefault();
sendReport("unhandledrejection", e instanceof Error ? {message: e.message, stack: e.stack} : e)
.catch(console.error)
}
});
}

/**
* Runtime init (sets ENV, storage, endpoint, ...)
Expand Down Expand Up @@ -100,6 +117,7 @@ export async function init() {
else Pointer.is_local = true;
})


// enable periodic pointer subscriber cleanup
Pointer.enablePeriodicSubscriberCleanup();

Expand Down Expand Up @@ -163,7 +181,7 @@ export async function init() {
// enables message logger when running with -v
if (verboseArg) MessageLogger.enable();

if (client_type == "deno") {
if (client_type == "deno" && !(globalThis as any).NO_INIT) {
const { clear } = await import("./utils/args.ts");
if (clear) {
await Storage.clearAndReload();
Expand Down

0 comments on commit 3cb3a9b

Please sign in to comment.