Skip to content
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

Rename OnSend to OnSendError #562

Merged
merged 2 commits into from
Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Bugsnag Notifiers on other platforms.

## Enhancements

* Rename `OnSend` to `OnSendError`
[#562](https://github.com/bugsnag/bugsnag-cocoa/pull/562)

* Add `onCrashHandler` data to `BugsnagEvent` metadata
[#564](https://github.com/bugsnag/bugsnag-cocoa/pull/564)

Expand Down
10 changes: 5 additions & 5 deletions Source/Bugsnag.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@
* @param block The block to be removed.
*/
+ (void)removeOnSessionBlock:(BugsnagOnSessionBlock _Nonnull)block
NS_SWIFT_NAME(removeOnSession(block:));;
NS_SWIFT_NAME(removeOnSession(block:));

// =============================================================================
// MARK: - onSend
Expand All @@ -268,16 +268,16 @@
*
* @param block A block which returns YES if the report should be sent
*/
+ (void)addOnSendBlock:(BugsnagOnSendBlock _Nonnull)block
NS_SWIFT_NAME(addOnSend(block:));
+ (void)addOnSendErrorBlock:(BugsnagOnSendErrorBlock _Nonnull)block
NS_SWIFT_NAME(addOnSendError(block:));

/**
* Remove the callback that would be invoked before an event is sent.
*
* @param block The block to be removed.
*/
+ (void)removeOnSendBlock:(BugsnagOnSendBlock _Nonnull)block
NS_SWIFT_NAME(removeOnSend(block:));
+ (void)removeOnSendErrorBlock:(BugsnagOnSendErrorBlock _Nonnull)block
NS_SWIFT_NAME(removeOnSendError(block:));

// =============================================================================
// MARK: - onBreadcrumb
Expand Down
8 changes: 4 additions & 4 deletions Source/Bugsnag.m
Original file line number Diff line number Diff line change
Expand Up @@ -357,17 +357,17 @@ + (void)updateCodeBundleId:(NSString *)codeBundleId {
// MARK: - onSend
// =============================================================================

+ (void)addOnSendBlock:(BugsnagOnSendBlock _Nonnull)block
+ (void)addOnSendErrorBlock:(BugsnagOnSendErrorBlock _Nonnull)block
{
if ([self bugsnagStarted]) {
[self.client addOnSendBlock:block];
[self.client addOnSendErrorBlock:block];
}
}

+ (void)removeOnSendBlock:(BugsnagOnSendBlock _Nonnull)block
+ (void)removeOnSendErrorBlock:(BugsnagOnSendErrorBlock _Nonnull)block
{
if ([self bugsnagStarted]) {
[self.client removeOnSendBlock:block];
[self.client removeOnSendErrorBlock:block];
}
}

Expand Down
18 changes: 12 additions & 6 deletions Source/BugsnagClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,16 @@ NS_SWIFT_NAME(leaveBreadcrumb(_:metadata:type:));
*
* @param block The block to be added.
*/
- (void)addOnSessionBlock:(BugsnagOnSessionBlock _Nonnull)block;
- (void)addOnSessionBlock:(BugsnagOnSessionBlock _Nonnull)block
NS_SWIFT_NAME(addOnSession(block:));

/**
* Remove a callback that would be invoked before a session is sent to Bugsnag.
*
* @param block The block to be removed.
*/
- (void)removeOnSessionBlock:(BugsnagOnSessionBlock _Nonnull )block;
- (void)removeOnSessionBlock:(BugsnagOnSessionBlock _Nonnull )block
NS_SWIFT_NAME(removeOnSession(block:));

// =============================================================================
// MARK: - Other methods
Expand Down Expand Up @@ -231,14 +233,16 @@ NS_SWIFT_NAME(leaveBreadcrumb(_:metadata:type:));
*
* @param block A block which returns YES if the report should be sent
*/
- (void)addOnSendBlock:(BugsnagOnSendBlock _Nonnull)block;
- (void)addOnSendErrorBlock:(BugsnagOnSendErrorBlock _Nonnull)block
NS_SWIFT_NAME(addOnSendError(block:));

/**
* Remove an onSend callback, if it exists
*
* @param block The block to remove
*/
- (void)removeOnSendBlock:(BugsnagOnSendBlock _Nonnull)block;
- (void)removeOnSendErrorBlock:(BugsnagOnSendErrorBlock _Nonnull)block
NS_SWIFT_NAME(removeOnSendError(block:));

// =============================================================================
// MARK: - onBreadcrumb
Expand All @@ -250,13 +254,15 @@ NS_SWIFT_NAME(leaveBreadcrumb(_:metadata:type:));
*
* @param block A block which returns YES if the breadcrumb should be captured
*/
- (void)addOnBreadcrumbBlock:(BugsnagOnBreadcrumbBlock _Nonnull)block;
- (void)addOnBreadcrumbBlock:(BugsnagOnBreadcrumbBlock _Nonnull)block
NS_SWIFT_NAME(addOnBreadcrumb(block:));

/**
* Remove the callback that would be invoked when a breadcrumb is captured.
*
* @param block The block to be removed.
*/
- (void)removeOnBreadcrumbBlock:(BugsnagOnBreadcrumbBlock _Nonnull)block;
- (void)removeOnBreadcrumbBlock:(BugsnagOnBreadcrumbBlock _Nonnull)block
NS_SWIFT_NAME(removeOnBreadcrumb(block:));

@end
8 changes: 4 additions & 4 deletions Source/BugsnagClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -748,12 +748,12 @@ - (void)removeOnSessionBlock:(BugsnagOnSessionBlock _Nonnull )block {
// MARK: - onSend
// =============================================================================

- (void)addOnSendBlock:(BugsnagOnSendBlock _Nonnull)block {
[self.configuration addOnSendBlock:block];
- (void)addOnSendErrorBlock:(BugsnagOnSendErrorBlock _Nonnull)block {
[self.configuration addOnSendErrorBlock:block];
}

- (void)removeOnSendBlock:(BugsnagOnSendBlock _Nonnull)block {
[self.configuration removeOnSendBlock:block];
- (void)removeOnSendErrorBlock:(BugsnagOnSendErrorBlock _Nonnull)block {
[self.configuration removeOnSendErrorBlock:block];
}

// =============================================================================
Expand Down
14 changes: 7 additions & 7 deletions Source/BugsnagConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ typedef BOOL (^BugsnagOnErrorBlock)(BugsnagEvent *_Nonnull event);
/**
* A handler for modifying data before sending it to Bugsnag.
*
* onSendBlocks will be invoked on a dedicated
* onSendErrorBlocks will be invoked on a dedicated
* background queue, which will be different from the queue where the block was originally added.
*
* @param event The event report.
*
* @return YES if the event should be sent
*/
typedef BOOL (^BugsnagOnSendBlock)(BugsnagEvent *_Nonnull event);
typedef BOOL (^BugsnagOnSendErrorBlock)(BugsnagEvent *_Nonnull event);

/**
* A configuration block for modifying a captured breadcrumb
Expand Down Expand Up @@ -283,7 +283,7 @@ typedef NS_OPTIONS(NSUInteger, BSGEnabledErrorType) {
* @param block The block to be removed.
*/
- (void)removeOnSessionBlock:(BugsnagOnSessionBlock _Nonnull)block
NS_SWIFT_NAME(removeOnSession(block:));;
NS_SWIFT_NAME(removeOnSession(block:));

// =============================================================================
// MARK: - onSend
Expand All @@ -295,16 +295,16 @@ typedef NS_OPTIONS(NSUInteger, BSGEnabledErrorType) {
*
* @param block A block which returns YES if the report should be sent
*/
- (void)addOnSendBlock:(BugsnagOnSendBlock _Nonnull)block
NS_SWIFT_NAME(addOnSend(block:));
- (void)addOnSendErrorBlock:(BugsnagOnSendErrorBlock _Nonnull)block
NS_SWIFT_NAME(addOnSendError(block:));

/**
* Remove the callback that would be invoked before an event is sent.
*
* @param block The block to be removed.
*/
- (void)removeOnSendBlock:(BugsnagOnSendBlock _Nonnull)block
NS_SWIFT_NAME(removeOnSend(block:));
- (void)removeOnSendErrorBlock:(BugsnagOnSendErrorBlock _Nonnull)block
NS_SWIFT_NAME(removeOnSendError(block:));

// =============================================================================
// MARK: - onBreadcrumb
Expand Down
4 changes: 2 additions & 2 deletions Source/BugsnagConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,11 @@ - (void)setUserMetadataFromUser:(BugsnagUser *)user {
// MARK: - onSendBlock
// =============================================================================

- (void)addOnSendBlock:(BugsnagOnSendBlock)block {
- (void)addOnSendErrorBlock:(BugsnagOnSendErrorBlock _Nonnull)block {
[(NSMutableArray *)self.onSendBlocks addObject:[block copy]];
}

- (void)removeOnSendBlock:(BugsnagOnSendBlock _Nonnull )block
- (void)removeOnSendErrorBlock:(BugsnagOnSendErrorBlock _Nonnull )block
{
[(NSMutableArray *)self.onSendBlocks removeObject:block];
}
Expand Down
2 changes: 1 addition & 1 deletion Source/BugsnagSink.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ - (void)filterReports:(NSDictionary <NSString *, NSDictionary *> *)reports
if (![bugsnagReport shouldBeSent])
continue;
BOOL shouldSend = YES;
for (BugsnagOnSendBlock block in configuration.onSendBlocks) {
for (BugsnagOnSendErrorBlock block in configuration.onSendBlocks) {
@try {
shouldSend = block(bugsnagReport);
if (!shouldSend)
Expand Down
4 changes: 3 additions & 1 deletion Tests/BugsnagBaseUnitTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ -(void)setUpBugsnagWillCallNotify:(bool)willNotify
[configuration setPersistUser:willPersistUser];

if (willNotify) {
[configuration addOnSendBlock:^BOOL(BugsnagEvent * _Nonnull event) { return false; }];
[configuration addOnSendErrorBlock:^BOOL(BugsnagEvent *_Nonnull event) {
return false;
}];
}
[Bugsnag startBugsnagWithConfiguration:configuration];
}
Expand Down
8 changes: 6 additions & 2 deletions Tests/BugsnagBreadcrumbsTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,9 @@ - (void)testBreadcrumbFromDict {
- (void)testCallbackFreeConstructors2 {
// Prevent sending events
BugsnagConfiguration *configuration = [[BugsnagConfiguration alloc] initWithApiKey:DUMMY_APIKEY_32CHAR_1];
[configuration addOnSendBlock:^BOOL(BugsnagEvent * _Nonnull event) { return false; }];
[configuration addOnSendErrorBlock:^BOOL(BugsnagEvent *_Nonnull event) {
return false;
}];
[Bugsnag startBugsnagWithConfiguration:configuration];

NSDictionary *md1 = @{ @"x" : @"y"};
Expand Down Expand Up @@ -369,7 +371,9 @@ - (void)testCallbackFreeConstructors2 {
- (void)testCallbackFreeConstructors3 {
// Prevent sending events
BugsnagConfiguration *configuration = [[BugsnagConfiguration alloc] initWithApiKey:DUMMY_APIKEY_32CHAR_1];
[configuration addOnSendBlock:^BOOL(BugsnagEvent * _Nonnull event) { return false; }];
[configuration addOnSendErrorBlock:^BOOL(BugsnagEvent *_Nonnull event) {
return false;
}];
[Bugsnag startBugsnagWithConfiguration:configuration];

[Bugsnag leaveBreadcrumbWithMessage:@"message1"];
Expand Down
4 changes: 3 additions & 1 deletion Tests/BugsnagClientTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ @implementation BugsnagClientTests
-(void)setUpBugsnagWillCallNotify:(bool)willNotify {
BugsnagConfiguration *configuration = [[BugsnagConfiguration alloc] initWithApiKey:DUMMY_APIKEY_32CHAR_1];
if (willNotify) {
[configuration addOnSendBlock:^BOOL(BugsnagEvent * _Nonnull event) { return false; }];
[configuration addOnSendErrorBlock:^BOOL(BugsnagEvent *_Nonnull event) {
return false;
}];
}
[Bugsnag startBugsnagWithConfiguration:configuration];
}
Expand Down
22 changes: 11 additions & 11 deletions Tests/BugsnagConfigurationTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -755,14 +755,14 @@ - (void) testRemoveOnSendBlock {
BugsnagConfiguration *configuration = [[BugsnagConfiguration alloc] initWithApiKey:DUMMY_APIKEY_32CHAR_1];
XCTAssertEqual([[configuration onSendBlocks] count], 0);

BugsnagOnSendBlock block = ^BOOL(BugsnagEvent * _Nonnull event) { return false; };
[configuration addOnSendBlock:block];
BugsnagOnSendErrorBlock block = ^BOOL(BugsnagEvent * _Nonnull event) { return false; };

[configuration addOnSendErrorBlock:block];
[Bugsnag startBugsnagWithConfiguration:configuration];

XCTAssertEqual([[configuration onSendBlocks] count], 1);
[configuration removeOnSendBlock:block];

[configuration removeOnSendErrorBlock:block];
XCTAssertEqual([[configuration onSendBlocks] count], 0);
}

Expand All @@ -774,12 +774,12 @@ - (void) testClearOnSendBlock {
BugsnagConfiguration *configuration = [[BugsnagConfiguration alloc] initWithApiKey:DUMMY_APIKEY_32CHAR_1];
XCTAssertEqual([[configuration onSendBlocks] count], 0);

BugsnagOnSendBlock block1 = ^BOOL(BugsnagEvent * _Nonnull event) { return false; };
BugsnagOnSendBlock block2 = ^BOOL(BugsnagEvent * _Nonnull event) { return false; };
BugsnagOnSendErrorBlock block1 = ^BOOL(BugsnagEvent * _Nonnull event) { return false; };
BugsnagOnSendErrorBlock block2 = ^BOOL(BugsnagEvent * _Nonnull event) { return false; };

// Add more than one
[configuration addOnSendBlock:block1];
[configuration addOnSendBlock:block2];
[configuration addOnSendErrorBlock:block1];
[configuration addOnSendErrorBlock:block2];

[Bugsnag startBugsnagWithConfiguration:configuration];

Expand All @@ -802,8 +802,8 @@ - (void)testNSCopying {
[config setAppType:@"The most amazing app, a brilliant app, the app to end all apps"];
[config setPersistUser:YES];
[config setSendThreads:BSGThreadSendPolicyUnhandledOnly];
BugsnagOnSendBlock onSendBlock1 = ^BOOL(BugsnagEvent * _Nonnull event) { return true; };
BugsnagOnSendBlock onSendBlock2 = ^BOOL(BugsnagEvent * _Nonnull event) { return true; };
BugsnagOnSendErrorBlock onSendBlock1 = ^BOOL(BugsnagEvent * _Nonnull event) { return true; };
BugsnagOnSendErrorBlock onSendBlock2 = ^BOOL(BugsnagEvent * _Nonnull event) { return true; };

NSArray *sendBlocks = @[ onSendBlock1, onSendBlock2 ];
[config setOnSendBlocks:[sendBlocks mutableCopy]]; // Mutable arg required
Expand Down
34 changes: 22 additions & 12 deletions Tests/BugsnagTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ @implementation BugsnagTests
-(void)setUpBugsnagWillCallNotify:(bool)willNotify {
BugsnagConfiguration *configuration = [[BugsnagConfiguration alloc] initWithApiKey:DUMMY_APIKEY_32CHAR_1];
if (willNotify) {
[configuration addOnSendBlock:^BOOL(BugsnagEvent * _Nonnull event) { return false; }];
[configuration addOnSendErrorBlock:^BOOL(BugsnagEvent *_Nonnull event) {
return false;
}];
}
[Bugsnag startBugsnagWithConfiguration:configuration];
}
Expand Down Expand Up @@ -147,7 +149,9 @@ - (void)testGetMetadata {
*/
-(void)testBugsnagPauseSession {
BugsnagConfiguration *configuration = [[BugsnagConfiguration alloc] initWithApiKey:DUMMY_APIKEY_32CHAR_1];
[configuration addOnSendBlock:^BOOL(BugsnagEvent * _Nonnull event) { return false; }];
[configuration addOnSendErrorBlock:^BOOL(BugsnagEvent *_Nonnull event) {
return false;
}];

[Bugsnag startBugsnagWithConfiguration:configuration];

Expand All @@ -164,7 +168,9 @@ - (void)testMutableContext {

BugsnagConfiguration *configuration = [[BugsnagConfiguration alloc] initWithApiKey:DUMMY_APIKEY_32CHAR_1];
[configuration setContext:@"firstContext"];
[configuration addOnSendBlock:^BOOL(BugsnagEvent * _Nonnull event) { return false; }];
[configuration addOnSendErrorBlock:^BOOL(BugsnagEvent *_Nonnull event) {
return false;
}];

[Bugsnag startBugsnagWithConfiguration:configuration];

Expand Down Expand Up @@ -249,7 +255,9 @@ - (void)testRemoveOnSessionBlock {
BugsnagConfiguration *configuration = [[BugsnagConfiguration alloc] initWithApiKey:DUMMY_APIKEY_32CHAR_1];

// non-sending bugsnag
[configuration addOnSendBlock:^BOOL(BugsnagEvent * _Nonnull event) { return false; }];
[configuration addOnSendErrorBlock:^BOOL(BugsnagEvent *_Nonnull event) {
return false;
}];

BugsnagOnSessionBlock sessionBlock = ^BOOL(BugsnagSession * _Nonnull sessionPayload) {
switch (called) {
Expand Down Expand Up @@ -290,7 +298,9 @@ - (void)testAddOnSessionBlock {
configuration.autoTrackSessions = NO;

// non-sending bugsnag
[configuration addOnSendBlock:^BOOL(BugsnagEvent * _Nonnull event) { return false; }];
[configuration addOnSendErrorBlock:^BOOL(BugsnagEvent *_Nonnull event) {
return false;
}];

BugsnagOnSessionBlock sessionBlock = ^BOOL(BugsnagSession * _Nonnull sessionPayload) {
switch (called) {
Expand Down Expand Up @@ -352,7 +362,7 @@ - (void) testOnSendBlocks {
expectation6.inverted = YES;

// Two blocks that will get called (or not) when we notify()
BugsnagOnSendBlock block1 = ^BOOL(BugsnagEvent * _Nonnull event)
BugsnagOnSendErrorBlock block1 = ^BOOL(BugsnagEvent * _Nonnull event)
{
switch (called) {
case 0:
Expand All @@ -376,7 +386,7 @@ - (void) testOnSendBlocks {
return false;
};

BugsnagOnSendBlock block2 = ^BOOL(BugsnagEvent * _Nonnull event)
BugsnagOnSendErrorBlock block2 = ^BOOL(BugsnagEvent * _Nonnull event)
{
switch (called) {
case 0:
Expand All @@ -403,9 +413,9 @@ - (void) testOnSendBlocks {
// Can't check for block behaviour before start(), so we don't

[Bugsnag startBugsnagWithConfiguration:configuration];
[Bugsnag addOnSendBlock:block1];
[Bugsnag addOnSendBlock:block2];

[Bugsnag addOnSendErrorBlock:block1];
[Bugsnag addOnSendErrorBlock:block2];

// Both added?
XCTAssertEqual([[[Bugsnag configuration] onSendBlocks] count], 2);
Expand All @@ -415,8 +425,8 @@ - (void) testOnSendBlocks {

// Both called?
[self waitForExpectations:@[expectation1, expectation2] timeout:10.0];
[Bugsnag removeOnSendBlock:block2];

[Bugsnag removeOnSendErrorBlock:block2];
XCTAssertEqual([[[Bugsnag configuration] onSendBlocks] count], 1);
called++;
XCTAssertEqual(called, 1);
Expand Down
Loading