Reporting handled exceptions

In order to quickly understand and fix some errors, it is often helpful to send additional diagnostic data which is specific to that error.

The notify and notifyError functions accept a block to modify the error report using a representation of the report which will be sent. Below are the available options for modifying the report.

The report object

context

Set the context of the error report. This is normally the location of the error and should be populated automatically. Context is displayed in the dashboard prominently.

[Bugsnag notify:exception block:^(BugsnagCrashReport *report) {
    report.context = @"XYZMenuController";
}];

depth

Set the number of frames discarded at the top of the stacktrace. By default, this value is the number of frames within Bugsnag’s library, but you can increase this number particularly if you have a single place to log errors and/or exceptions and wish to avoid grouping in that function.

void logError(NSError *error) {
    [Bugsnag notifyError:error block:^(BugsnagCrashReport *report) {
        // Increment for the function, the notify call, and the block
        report.depth += 3;
    }];
}

errorClass

The type of the error which generated the report. This should be populated automatically with the class name of the error.

[Bugsnag notify:exception block:^(BugsnagCrashReport *report) {
    report.errorClass = @"Authentication failed";
}];

errorMessage

The message or description of the error which generated the report.

[Bugsnag notify:exception block:^(BugsnagCrashReport *report) {
    report.errorMessage = @"Username rejected by the auth server";
}];

groupingHash

Sets the grouping hash of the error report. All errors with the same grouping hash are grouped together. This is an advanced usage of the library and mis-using it will cause your errors not to group properly in your dashboard.

[Bugsnag notify:exception block:^(BugsnagCrashReport *report) {
    report.groupingHash = @"unexpected-auth-failures";
}];

metaData

The metaData property is mapped to the metadata tabs on a reports in the Bugsnag dashboard. Each top level key indicates an additional tab. To attach additional diagnostic data to a report, use the addMetadata method, which merges added data into the existing metadata in a report.

[Bugsnag notify:exception block:^(BugsnagCrashReport *report) {
    NSDictionary *meals = @{
        @"breakfast": @"toast and eggs",
        @"lunch": @"hamburger"
    };
    [report addMetadata:meals toTabWithName:@"meals"];
    // use addAttribute:withValue:toTabWithName: to add an individual value
    [report addAttribute:@"dessert" withValue:@"cake" toTabWithName:@"meals"];
}];

To edit and remove diagnostic data included in a report, edit the metaData property directly.

[Bugsnag notify:exception block:^(BugsnagCrashReport *report) {
    NSMutableDictionary *metadata = report.metaData.mutableCopy;
    NSMutableDictionary *supportInfo = [metadata[@"support-info"] mutableCopy];
    [food removeObjectForKey:@"password"];
    metadata[@"support-info"] = food;
    report.metaData = metadata;
}];

releaseStage

The stage of development of the application currently running.

[Bugsnag notify:exception block:^(BugsnagCrashReport *report) {
    report.releaseStage = @"beta-group-23";
}];

severity

A rating of how critical an error report is.

[Bugsnag notify:exception block:^(BugsnagCrashReport *report) {
    report.severity = BSGSeverityError;
}];