Skip to content

Commit 10f52e1

Browse files
committed
fix(kernel): silence unhandled promise rejections when checking for async services
1 parent de26a2e commit 10f52e1

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@objectstack/core": patch
3+
---
4+
5+
fix: silence unhandled promise rejections when checking for async services in kernel

packages/core/src/kernel.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ export class ObjectKernel {
9494
const service = this.pluginLoader.getService(name);
9595
if (service instanceof Promise) {
9696
// If we found it in the loader but not in the sync map, it's likely a factory-based service or still loading
97+
// We must silence any potential rejection from this promise since we are about to throw our own error
98+
// and abandon the promise. Without this, Node.js will crash with "Unhandled Promise Rejection".
99+
service.catch(() => {});
97100
throw new Error(`Service '${name}' is async - use await`);
98101
}
99102
return service as T;

0 commit comments

Comments
 (0)