Skip to content

Commit

Permalink
Make error reports more customizable (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
kattrali authored Jul 22, 2016
2 parents 7176d4f + 6b4a7ff commit 7e93115
Show file tree
Hide file tree
Showing 20 changed files with 941 additions and 291 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "Carthage/Checkouts/KSCrash"]
path = Carthage/Checkouts/KSCrash
url = https://github.com/kstenerud/KSCrash
[submodule "development/Kiwi"]
path = development/Kiwi
url = https://github.com/kiwi-bdd/Kiwi
2 changes: 1 addition & 1 deletion Bugsnag.podspec.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"requires_arc": true,
"public_header_files": [
"Source/BSGKSCrashReportWriter.h",
"Source/Bugsnag{,MetaData,Configuration,Breadcrumb}.h"
"Source/Bugsnag{,MetaData,Configuration,Breadcrumb,CrashReport}.h"
],
"dependencies": {
"KSCrash/RecordingAdvanced": [
Expand Down
3 changes: 3 additions & 0 deletions OSX.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions OSX.xcworkspace/xcshareddata/OSX.xcscmblueprint
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,25 @@

},
"DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : {
"4FD7C20106F5BD91089CFF7BC197AC2E448D173B" : 0,
"D2885296440547CB23891301E79B480A22EAC5F6" : 0,
"C4519EFDD2C3B96E9BD67A5CED575450FFB87C90" : 0
},
"DVTSourceControlWorkspaceBlueprintIdentifierKey" : "64F71D72-7937-47C7-9FA1-099F1EFA7F49",
"DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : {
"4FD7C20106F5BD91089CFF7BC197AC2E448D173B" : "bugsnag-cocoa\/development\/Kiwi\/",
"D2885296440547CB23891301E79B480A22EAC5F6" : "bugsnag-cocoa-r\/Carthage\/Checkouts\/KSCrash\/",
"C4519EFDD2C3B96E9BD67A5CED575450FFB87C90" : "bugsnag-cocoa-r\/"
},
"DVTSourceControlWorkspaceBlueprintNameKey" : "OSX",
"DVTSourceControlWorkspaceBlueprintVersion" : 204,
"DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "OSX.xcworkspace",
"DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [
{
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/kiwi-bdd\/Kiwi",
"DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "4FD7C20106F5BD91089CFF7BC197AC2E448D173B"
},
{
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "github.com:bugsnag\/bugsnag-cocoa",
"DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",
Expand Down
12 changes: 10 additions & 2 deletions OSX/Bugsnag.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
8A2C8FD21C6BC2C800846019 /* BugsnagCollections.m in Sources */ = {isa = PBXBuildFile; fileRef = 8A2C8FC01C6BC2C800846019 /* BugsnagCollections.m */; };
8A2C8FD31C6BC2C800846019 /* BugsnagConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = 8A2C8FC11C6BC2C800846019 /* BugsnagConfiguration.h */; settings = {ATTRIBUTES = (Public, ); }; };
8A2C8FD41C6BC2C800846019 /* BugsnagConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = 8A2C8FC21C6BC2C800846019 /* BugsnagConfiguration.m */; };
8A2C8FD51C6BC2C800846019 /* BugsnagCrashReport.h in Headers */ = {isa = PBXBuildFile; fileRef = 8A2C8FC31C6BC2C800846019 /* BugsnagCrashReport.h */; };
8A2C8FD51C6BC2C800846019 /* BugsnagCrashReport.h in Headers */ = {isa = PBXBuildFile; fileRef = 8A2C8FC31C6BC2C800846019 /* BugsnagCrashReport.h */; settings = {ATTRIBUTES = (Public, ); }; };
8A2C8FD61C6BC2C800846019 /* BugsnagCrashReport.m in Sources */ = {isa = PBXBuildFile; fileRef = 8A2C8FC41C6BC2C800846019 /* BugsnagCrashReport.m */; };
8A2C8FD71C6BC2C800846019 /* BugsnagMetaData.h in Headers */ = {isa = PBXBuildFile; fileRef = 8A2C8FC51C6BC2C800846019 /* BugsnagMetaData.h */; settings = {ATTRIBUTES = (Public, ); }; };
8A2C8FD81C6BC2C800846019 /* BugsnagMetaData.m in Sources */ = {isa = PBXBuildFile; fileRef = 8A2C8FC61C6BC2C800846019 /* BugsnagMetaData.m */; };
Expand All @@ -31,6 +31,8 @@
8A2C8FF01C6BC3A200846019 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A2C8FEF1C6BC3A200846019 /* SystemConfiguration.framework */; };
8A2C90031C6BC3FA00846019 /* libKSCrashLib.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A2C90021C6BC3FA00846019 /* libKSCrashLib.a */; };
8A2C90441C6C040700846019 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A2C90401C6C03F000846019 /* Cocoa.framework */; };
8A7630E21D2523AE000D6737 /* Kiwi.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A7630E11D2523AE000D6737 /* Kiwi.framework */; };
8A7630E51D2524DB000D6737 /* BugsnagSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 8A7630DF1D252309000D6737 /* BugsnagSpec.m */; };
8A87352C1C6D3B1600EDBD5B /* BSGKSCrashReportWriter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8A87352B1C6D3B1600EDBD5B /* BSGKSCrashReportWriter.h */; settings = {ATTRIBUTES = (Public, ); }; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -76,6 +78,8 @@
8A2C902F1C6BF3AC00846019 /* module.modulemap */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = "sourcecode.module-map"; path = module.modulemap; sourceTree = SOURCE_ROOT; };
8A2C90401C6C03F000846019 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
8A2C90421C6C03FF00846019 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
8A7630DF1D252309000D6737 /* BugsnagSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BugsnagSpec.m; path = ../Tests/BugsnagSpec.m; sourceTree = SOURCE_ROOT; };
8A7630E11D2523AE000D6737 /* Kiwi.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Kiwi.framework; path = "../../../../../Library/Developer/Xcode/DerivedData/OSX-fywomumlxcstijawyihsvjfwghcm/Build/Products/Debug/Kiwi.framework"; sourceTree = "<group>"; };
8A87352B1C6D3B1600EDBD5B /* BSGKSCrashReportWriter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BSGKSCrashReportWriter.h; path = ../Source/BSGKSCrashReportWriter.h; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */

Expand All @@ -94,6 +98,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
8A7630E21D2523AE000D6737 /* Kiwi.framework in Frameworks */,
8A2C8FAC1C6BC1F700846019 /* Bugsnag.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -151,6 +156,7 @@
children = (
8A2C8FE01C6BC38200846019 /* BugsnagBreadcrumbsTest.m */,
8A2C8FE11C6BC38200846019 /* BugsnagCrashReportTests.m */,
8A7630DF1D252309000D6737 /* BugsnagSpec.m */,
8A2C8FE21C6BC38200846019 /* BugsnagSinkTests.m */,
8A2C8FE41C6BC38200846019 /* report.json */,
8A2C8FB21C6BC1F700846019 /* TestsInfo.plist */,
Expand All @@ -162,6 +168,7 @@
8A2C8FF51C6BC3C200846019 /* Frameworks */ = {
isa = PBXGroup;
children = (
8A7630E11D2523AE000D6737 /* Kiwi.framework */,
8A2C90421C6C03FF00846019 /* Foundation.framework */,
8A2C90401C6C03F000846019 /* Cocoa.framework */,
8A2C90021C6BC3FA00846019 /* libKSCrashLib.a */,
Expand All @@ -183,10 +190,10 @@
8A2C8FD71C6BC2C800846019 /* BugsnagMetaData.h in Headers */,
8A2C8FCD1C6BC2C800846019 /* Bugsnag.h in Headers */,
8A2C8FCF1C6BC2C800846019 /* BugsnagBreadcrumb.h in Headers */,
8A2C8FD51C6BC2C800846019 /* BugsnagCrashReport.h in Headers */,
8A2C8FD91C6BC2C800846019 /* BugsnagNotifier.h in Headers */,
8A2C8FDD1C6BC2C800846019 /* BugsnagSink.h in Headers */,
8A87352C1C6D3B1600EDBD5B /* BSGKSCrashReportWriter.h in Headers */,
8A2C8FD51C6BC2C800846019 /* BugsnagCrashReport.h in Headers */,
8A2C8FD31C6BC2C800846019 /* BugsnagConfiguration.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -305,6 +312,7 @@
files = (
8A2C8FEA1C6BC38900846019 /* BugsnagBreadcrumbsTest.m in Sources */,
8A2C8FEC1C6BC38900846019 /* BugsnagSinkTests.m in Sources */,
8A7630E51D2524DB000D6737 /* BugsnagSpec.m in Sources */,
8A2C8FEB1C6BC38900846019 /* BugsnagCrashReportTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
31 changes: 29 additions & 2 deletions Source/Bugsnag.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,31 @@ static NSString *_Nonnull const BugsnagSeverityInfo = @"info";
*/
+ (void)notify:(NSException *_Nonnull)exception;

/**
* Send a custom or caught exception to Bugsnag
*
* @param exception The exception
* @param block A block for optionally configuring the error report
*/
+ (void)notify:(NSException *_Nonnull)exception
block:(BugsnagNotifyBlock _Nullable)block;

/**
* Send an error to Bugsnag
*
* @param error The error
*/
+ (void)notifyError:(NSError *_Nonnull)error;

/**
* Send an error to Bugsnag
*
* @param error The error
* @param block A block for optionally configuring the error report
*/
+ (void)notifyError:(NSError *_Nonnull)error
block:(BugsnagNotifyBlock _Nullable)block;

/** Send a custom or caught exception to Bugsnag.
*
* The exception will be sent to Bugsnag in the background allowing your
Expand All @@ -87,7 +112,8 @@ static NSString *_Nonnull const BugsnagSeverityInfo = @"info";
* report.
*/
+ (void)notify:(NSException *_Nonnull)exception
withData:(NSDictionary *_Nullable)metaData;
withData:(NSDictionary *_Nullable)metaData
__deprecated_msg("Use notify:block: instead and add the metadata to the report directly.");

/** Send a custom or caught exception to Bugsnag.
*
Expand All @@ -103,7 +129,8 @@ static NSString *_Nonnull const BugsnagSeverityInfo = @"info";
*/
+ (void)notify:(NSException *_Nonnull)exception
withData:(NSDictionary *_Nullable)metaData
atSeverity:(NSString *_Nullable)severity;
atSeverity:(NSString *_Nullable)severity
__deprecated_msg("Use notify:block: instead and add the metadata and severity to the report directly.");

/** Add custom data to send to Bugsnag with every exception. If value is nil,
* delete the current value for attributeName
Expand Down
116 changes: 109 additions & 7 deletions Source/Bugsnag.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#import "Bugsnag.h"
#import "BugsnagBreadcrumb.h"
#import "BugsnagConfiguration.h"
#import "BugsnagCrashReport.h"
#import "BugsnagNotifier.h"
#import "BugsnagSink.h"
#import <KSCrash/KSCrashAdvanced.h>
Expand All @@ -38,12 +39,15 @@ + (BugsnagNotifier*)notifier;
+ (BOOL) bugsnagStarted;
@end

@interface NSDictionary (BSGKSMerge)
- (NSDictionary*)BSG_mergedInto:(NSDictionary *)dest;
@end

@implementation Bugsnag

+ (void)startBugsnagWithApiKey:(NSString*)apiKey {
BugsnagConfiguration *configuration = [[BugsnagConfiguration alloc] init];
BugsnagConfiguration *configuration = [BugsnagConfiguration new];
configuration.apiKey = apiKey;

[self startBugsnagWithConfiguration:configuration];
}

Expand All @@ -68,15 +72,57 @@ + (BugsnagNotifier*)notifier {
}

+ (void) notify:(NSException *)exception {
[self.notifier notify:exception withData:nil atSeverity: BugsnagSeverityWarning atDepth: 1];
[self.notifier notifyException:exception
block:^(BugsnagCrashReport * _Nonnull report) {
report.depth = 1;
}];
}

+ (void) notify:(NSException *)exception withData:(NSDictionary*)metaData {
[self.notifier notify:exception withData:metaData atSeverity: BugsnagSeverityWarning atDepth: 1];
+ (void)notify:(NSException *)exception block:(BugsnagNotifyBlock)block {
[[self notifier] notifyException:exception
block:^(BugsnagCrashReport * _Nonnull report) {
report.depth = 1;
if (block)
block(report);
}];
}

+ (void) notify:(NSException *)exception withData:(NSDictionary*)metaData atSeverity:(NSString*)severity {
[self.notifier notify:exception withData:metaData atSeverity: severity atDepth: 1];
+ (void) notifyError:(NSError *)error {
[self.notifier notifyError:error
block:^(BugsnagCrashReport * _Nonnull report) {
report.depth = 1;
}];
}


+ (void)notifyError:(NSError *)error block:(BugsnagNotifyBlock)block {
[[self notifier] notifyError:error
block:^(BugsnagCrashReport * _Nonnull report) {
report.depth = 1;
if (block)
block(report);
}];
}

+ (void)notify:(NSException *)exception withData:(NSDictionary*)metaData {
[[self notifier] notifyException:exception
block:^(BugsnagCrashReport * _Nonnull report) {
report.depth = 1;
report.metaData = [metaData BSG_mergedInto:
[self.notifier.configuration.metaData toDictionary]];
}];
}

+ (void)notify:(NSException *)exception
withData:(NSDictionary*)metaData
atSeverity:(NSString*)severity {
[[self notifier] notifyException:exception
block:^(BugsnagCrashReport * _Nonnull report) {
report.depth = 1;
report.metaData = [metaData BSG_mergedInto:
[self.notifier.configuration.metaData toDictionary]];
report.severity = BSGParseSeverity(severity);
}];
}

+ (void) addAttribute:(NSString*)attributeName withValue:(id)value toTabWithName:(NSString*)tabName {
Expand Down Expand Up @@ -125,3 +171,59 @@ + (NSDateFormatter *)payloadDateFormatter {
}

@end

//
// NSDictionary+Merge.m
//
// Created by Karl Stenerud on 2012-10-01.
//
// Copyright (c) 2012 Karl Stenerud. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall remain in place
// in this source code.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

@implementation NSDictionary (BSGKSMerge)

- (NSDictionary*)BSG_mergedInto:(NSDictionary *)dest
{
if([dest count] == 0)
{
return self;
}
if([self count] == 0)
{
return dest;
}

NSMutableDictionary* dict = [dest mutableCopy];
for(id key in [self allKeys])
{
id srcEntry = [self objectForKey:key];
id dstEntry = [dest objectForKey:key];
if([dstEntry isKindOfClass:[NSDictionary class]] &&
[srcEntry isKindOfClass:[NSDictionary class]])
{
srcEntry = [srcEntry BSG_mergedInto:dstEntry];
}
[dict setObject:srcEntry forKey:key];
}
return dict;
}

@end
Loading

0 comments on commit 7e93115

Please sign in to comment.