-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(#146): do not swallow uncaught exception/unhandled rejection when…
… importing the EdgeRuntime module
- Loading branch information
Showing
9 changed files
with
140 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@edge-runtime/vm': patch | ||
--- | ||
|
||
Do not swallow uncaught exception/unhandled rejection when importing the EdgeRuntime module. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { EdgeRuntime } from '../../src' | ||
|
||
new EdgeRuntime() | ||
throw new Error('intentional break') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { EdgeRuntime } from '../../src' | ||
|
||
new EdgeRuntime() | ||
Promise.reject(new Error('intentional break')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { EdgeRuntime } from '../../src' | ||
import assert from 'assert' | ||
|
||
function main() { | ||
const runtime = new EdgeRuntime() | ||
runtime.context.handleError = (error: Error) => { | ||
assert.strictEqual(error?.message, 'expected error') | ||
console.log('TEST PASSED!') | ||
} | ||
|
||
runtime.evaluate(` | ||
addEventListener('error', (error) => { | ||
globalThis.handleError(error) | ||
}) | ||
throw new Error('expected error') | ||
`) | ||
} | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { exec } from 'child_process' | ||
import { promisify } from 'util' | ||
import { resolve } from 'path' | ||
|
||
jest.setTimeout(2000) | ||
const execAsync = promisify(exec) | ||
|
||
it('handles correctly unhandled rejections', async () => { | ||
const result = await execAsync( | ||
`ts-node --transpile-only ${resolve( | ||
__dirname, | ||
'./fixtures/unhandled-rejection.ts' | ||
)}`, | ||
{ encoding: 'utf8' } | ||
) | ||
expect(result).toMatchObject({ | ||
stdout: expect.stringContaining('TEST PASSED!'), | ||
stderr: '', | ||
}) | ||
}) | ||
|
||
it('handles correctly uncaught exceptions', async () => { | ||
const result = await execAsync( | ||
`ts-node --transpile-only ${resolve( | ||
__dirname, | ||
'./fixtures/uncaught-exception.ts' | ||
)}`, | ||
{ encoding: 'utf8' } | ||
) | ||
expect(result).toMatchObject({ | ||
stdout: expect.stringContaining('TEST PASSED!'), | ||
stderr: '', | ||
}) | ||
}) | ||
|
||
it('does not swallow uncaught exceptions outside of evaluation', async () => { | ||
const execAsync = promisify(exec) | ||
await expect( | ||
execAsync( | ||
`ts-node --transpile-only ${resolve( | ||
__dirname, | ||
'./fixtures/legit-uncaught-exception.ts' | ||
)}`, | ||
{ encoding: 'utf8' } | ||
) | ||
).rejects.toThrow(/intentional break/) | ||
}) | ||
|
||
it('does not swallow unhandled rejections outside of evaluation', async () => { | ||
const execAsync = promisify(exec) | ||
await expect( | ||
execAsync( | ||
`ts-node --transpile-only ${resolve( | ||
__dirname, | ||
'./fixtures/legit-unhandled-rejection.ts' | ||
)}`, | ||
{ encoding: 'utf8' } | ||
) | ||
).rejects.toThrow(/intentional break/) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters