Skip to main content

Crash reporting

API BackendTooling

Report important environmental information when an error occurs or a process crashes.

Installation

yarn add @boost/debug

Reporting

Sometimes an application or script fails. Sometimes we want to write an error log with environmental information about the failure. Boost supports this exact scenario.

Take advantage of crash reporting by importing and instantiating the CrashReporter class.

import { CrashReporter } from '@boost/debug';

const reporter = new CrashReporter();

The reporter supports a collection of chainable methods that log targeted information, grouped into sections. View the API for more information on these methods.

reporter
.reportPackageVersions('@boost/*')
.reportBinaries()
.reportEnvVars()
.reportSystem();

If you'd like to add your own section and label value pairs, use CrashReporter#addSection(), which requires a title, and CrashReporter#add(), which accepts a label and one or many values.

reporter
.addSection('User')
.add('ID', user.id)
.add('Name', user.name)
.add('Location', user.address, user.country);

Once all the information has been buffered, we can write the content to a log file by using CrashReporter#write(), which requires an absolute file path.

reporter.write(path.join(process.cwd(), 'error.log'));