File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed
Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,8 @@ import { Logger } from './Logger'
33const logger = new Logger ( module )
44
55/**
6- * Execute a promise that should never reject. If it does, log the error and exit the process.
6+ * Execute a promise that should never reject. If it does, log the error and exit the process
7+ * (in Node/Electron) or throw an unhandled error (in browsers).
78 * To be used in places where we want to "annotate" that the intention of a promise is never
89 * to reject (unless something is really wrong).
910 */
@@ -12,11 +13,13 @@ export const executeSafePromise = async <T>(createPromise: () => Promise<T>): Pr
1213 return await createPromise ( )
1314 } catch ( err : any ) {
1415 logger . fatal ( 'Assertion failure!' , { message : err ?. message , err } )
15- if ( process . exit !== undefined ) {
16+
17+ // Check if we're in a Node/Electron environment
18+ if ( typeof process !== 'undefined' && process . exit !== undefined ) {
1619 process . exit ( 1 )
1720 } else {
18- // cause an unhandled promise rejection on purpose
19- throw new Error ( 'executeSafePromise: Assertion failure!' , err )
21+ // Browser environment - throw with proper error chaining
22+ throw new Error ( 'executeSafePromise: Assertion failure!' , { cause : err } )
2023 }
2124 }
2225}
You can’t perform that action at this time.
0 commit comments