Skip to content

Commit

Permalink
Merge pull request #325 from vim-denops/fix-unhandled-error
Browse files Browse the repository at this point in the history
🐛 Fix denops crash on UnhandledRejection error
  • Loading branch information
lambdalisue authored Feb 29, 2024
2 parents 17fc843 + 8b92254 commit b5dfcbc
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions denops/@denops-private/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ async function main(): Promise<void> {
...formatArgs(args),
);
};

// Start service
using service = new Service(meta);
await host.init(service);
Expand All @@ -83,6 +84,12 @@ async function main(): Promise<void> {
}

if (import.meta.main) {
// Avoid denops server crash via UnhandledRejection
globalThis.addEventListener("unhandledrejection", (event) => {
event.preventDefault();
console.error(`Unhandled rejection:`, event.reason);
});

await main().catch((err) => {
console.error(
`Internal error occurred in Worker`,
Expand Down

0 comments on commit b5dfcbc

Please sign in to comment.