-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(node): Add option to OnUncaughtException
integration that allows mimicking native uncaught error exit behaviour
#6137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const Sentry = require('@sentry/node'); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
}); | ||
|
||
process.on('uncaughtException', () => { | ||
// do nothing - this will prevent the Error below from closing this process before the timeout resolves | ||
}); | ||
|
||
setTimeout(() => { | ||
process.stdout.write("I'm alive!"); | ||
process.exit(0); | ||
}, 500); | ||
|
||
throw new Error(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const Sentry = require('@sentry/node'); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
integrations: integrations => { | ||
return integrations.map(integration => { | ||
if (integration.name === 'OnUncaughtException') { | ||
return new Sentry.Integrations.OnUncaughtException({ | ||
exitEvenWhenOtherOnUncaughtExceptionHandlersAreRegistered: false, | ||
}); | ||
} else { | ||
return integration; | ||
} | ||
}); | ||
}, | ||
}); | ||
|
||
process.on('uncaughtException', () => { | ||
// do nothing - this will prevent the Error below from closing this process before the timeout resolves | ||
}); | ||
|
||
setTimeout(() => { | ||
process.stdout.write("I'm alive!"); | ||
process.exit(0); | ||
}, 500); | ||
|
||
throw new Error(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const Sentry = require('@sentry/node'); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
integrations: integrations => { | ||
return integrations.map(integration => { | ||
if (integration.name === 'OnUncaughtException') { | ||
return new Sentry.Integrations.OnUncaughtException({ | ||
exitEvenWhenOtherOnUncaughtExceptionHandlersAreRegistered: false, | ||
}); | ||
} else { | ||
return integration; | ||
} | ||
}); | ||
}, | ||
}); | ||
|
||
setTimeout(() => { | ||
// This should not be called because the script throws before this resolves | ||
process.stdout.write("I'm alive!"); | ||
process.exit(0); | ||
}, 500); | ||
|
||
throw new Error(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const Sentry = require('@sentry/node'); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
}); | ||
|
||
setTimeout(() => { | ||
// This should not be called because the script throws before this resolves | ||
process.stdout.write("I'm alive!"); | ||
process.exit(0); | ||
}, 500); | ||
|
||
throw new Error(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import * as childProcess from 'child_process'; | ||
import * as path from 'path'; | ||
|
||
describe('OnUncaughtException integration', () => { | ||
test('should close process on uncaught error with no additional listeners registered', done => { | ||
expect.assertions(3); | ||
|
||
const testScriptPath = path.resolve(__dirname, 'no-additional-listener-test-script.js'); | ||
|
||
childProcess.exec(`node ${testScriptPath}`, { encoding: 'utf8' }, (err, stdout) => { | ||
Check warningCode scanning / CodeQL Shell command built from environment values
This shell command depends on an uncontrolled [absolute path](1).
|
||
expect(err).not.toBeNull(); | ||
expect(err?.code).toBe(1); | ||
expect(stdout).not.toBe("I'm alive!"); | ||
done(); | ||
}); | ||
}); | ||
|
||
test('should close process on uncaught error when additional listeners are registered', done => { | ||
expect.assertions(3); | ||
|
||
const testScriptPath = path.resolve(__dirname, 'additional-listener-test-script.js'); | ||
|
||
childProcess.exec(`node ${testScriptPath}`, { encoding: 'utf8' }, (err, stdout) => { | ||
Check warningCode scanning / CodeQL Shell command built from environment values
This shell command depends on an uncontrolled [absolute path](1).
|
||
expect(err).not.toBeNull(); | ||
expect(err?.code).toBe(1); | ||
expect(stdout).not.toBe("I'm alive!"); | ||
done(); | ||
}); | ||
}); | ||
|
||
describe('with `exitEvenWhenOtherOnUncaughtExceptionHandlersAreRegistered` set to false', () => { | ||
test('should close process on uncaught error with no additional listeners registered', done => { | ||
expect.assertions(3); | ||
|
||
const testScriptPath = path.resolve(__dirname, 'mimic-native-behaviour-no-additional-listener-test-script.js'); | ||
|
||
childProcess.exec(`node ${testScriptPath}`, { encoding: 'utf8' }, (err, stdout) => { | ||
Check warningCode scanning / CodeQL Shell command built from environment values
This shell command depends on an uncontrolled [absolute path](1).
|
||
expect(err).not.toBeNull(); | ||
expect(err?.code).toBe(1); | ||
expect(stdout).not.toBe("I'm alive!"); | ||
done(); | ||
}); | ||
}); | ||
|
||
test('should not close process on uncaught error when additional listeners are registered', done => { | ||
expect.assertions(2); | ||
|
||
const testScriptPath = path.resolve(__dirname, 'mimic-native-behaviour-additional-listener-test-script.js'); | ||
|
||
childProcess.exec(`node ${testScriptPath}`, { encoding: 'utf8' }, (err, stdout) => { | ||
Check warningCode scanning / CodeQL Shell command built from environment values
This shell command depends on an uncontrolled [absolute path](1).
|
||
expect(err).toBeNull(); | ||
expect(stdout).toBe("I'm alive!"); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
Uh oh!
There was an error while loading. Please reload this page.