-
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 (#222)
- Loading branch information
Showing
12 changed files
with
153 additions
and
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,6 @@ on: | |
pull_request: | ||
branches: [main] | ||
|
||
env: | ||
FORCE_COLOR: 1 | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
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
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,69 @@ | ||
import { exec } from 'child_process' | ||
import { promisify } from 'util' | ||
import { resolve } from 'path' | ||
|
||
jest.setTimeout(20000) | ||
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.only('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', | ||
env: process.version.startsWith('v14') | ||
? { | ||
...process.env, | ||
// node 14 does not throw on unhandled rejections, so this test would resolve without the flag | ||
'NODE_OPTIONS': '--unhandled-rejections=strict', | ||
} | ||
: undefined, | ||
} | ||
) | ||
).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
90b1e6f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
edge-runtime – ./
edge-runtime.vercel.app
edge-runtime.vercel.sh
edge-runtime-git-main.vercel.sh