Skip to content

Commit

Permalink
use browser exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
omochi committed May 24, 2024
1 parent dc4ac45 commit 6833478
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Sources/CartonKit/Server/StaticArchive.swift

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Tests/Fixtures/SandboxApp/Sources/app/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func fputs(_ string: String, file: FILEPointer) {
fputs("hello stdout\n", file: stdout)
fputs("hello stderr\n", file: stderr)

//fatalError("hello fatalError")
fatalError("hello fatalError")

let document = JSObject.global.document

Expand Down
10 changes: 1 addition & 9 deletions entrypoint/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,8 @@ const startWasiTask = async () => {
await wasmRunner.run(wasmBytes);
};

function handleError(e: any) {
console.error(e);
}

async function main(): Promise<void> {
try {
await startWasiTask();
} catch (e) {
handleError(e);
}
await startWasiTask();
}

main();
5 changes: 1 addition & 4 deletions entrypoint/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ const startWasiTask = async () => {
};

function handleError(e: any) {
console.error(e);

if (e instanceof Error) {
const stack = e.stack;
if (stack != null) {
Expand All @@ -78,16 +76,15 @@ function handleError(e: any) {
async function main(): Promise<void> {
try {
window.addEventListener("error", (event) => {
event.preventDefault();
handleError(event.error);
});
window.addEventListener("unhandledrejection", (event) => {
event.preventDefault();
handleError(event.reason);
});
await startWasiTask();
} catch (e) {
handleError(e);
throw e;
}
}

Expand Down

0 comments on commit 6833478

Please sign in to comment.