Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
@dotcom-reliability-kit/crash-handler
Advanced tools
A method to bind an uncaught exception handler to ensure that fatal application errors are logged
A method to bind an uncaught exception handler to ensure that fatal application errors are logged. It is a replacement for Sentry fatal error logging. This module is part of FT.com Reliability Kit.
Install @dotcom-reliability-kit/crash-handler
as a dependency:
npm install --save @dotcom-reliability-kit/crash-handler
Include in your code:
import registerCrashHandler from '@dotcom-reliability-kit/crash-handler';
// or
const registerCrashHandler = require('@dotcom-reliability-kit/crash-handler');
registerCrashHandler
The registerCrashHandler
function can be used to bind an event handler to the Node.js process.uncaughtException
event. This ensures that your application logs a final message before crashing in the event on an unexpected error or promise rejection.
This function should only ever be called once in your app, normally alongside all your setup code (e.g. alongside creating an Express app).
Note It's not a requirement, but generally the earlier the better with registering an uncaught exception handler – the sooner you register it the more likely you are to catch uncaught exceptions.
registerCrashHandler();
If an error is thrown which will crash your application, error information will be logged and then the process will exit with the value of process.exitCode
or 1
.
Warning This function will not work as expected if your app is using n-raven or n-express without the
withSentry
option set tofalse
. This is because the way we set up Sentry prevents registering any other uncaught exception handlers. You'll need to migrate away from Sentry to use this module.
Config options can be passed into the registerCrashHandler
function as an object with any of the keys below.
registerCrashHandler({
// Config options go here
});
options.logger
A logger object which implements two methods, error
and warn
, which have the following permissive signature:
type LogMethod = (...logData: any) => any;
This is passed directly onto the relevant log-error method, see the documentation for that package for more details.
options.process
The Node.js Process object to bind the error handling event to. You may use this if you are using a child process or want to mock the process object in your tests.
registerCrashHandler({
process: myProcessObject
});
The Reliability Kit crash handler is a replacement for Sentry's uncaught exception handling, which your app is likely to be using. You'll need to migrate away from Sentry in order to use this module. We maintain a migration guide for this on Confluence.
See the central contributing guide for Reliability Kit.
Licensed under the MIT license.
Copyright © 2022, The Financial Times Ltd.
FAQs
A method to bind an uncaught exception handler to ensure that fatal application errors are logged
The npm package @dotcom-reliability-kit/crash-handler receives a total of 755 weekly downloads. As such, @dotcom-reliability-kit/crash-handler popularity was classified as not popular.
We found that @dotcom-reliability-kit/crash-handler demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.