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

Remove unused APIs on BugsnagEvent interface #498

Merged
merged 5 commits into from
Mar 27, 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

* Remove unused APIs on `BugsnagEvent` interface
[#498](https://github.com/bugsnag/bugsnag-cocoa/pull/498)

* Remove unused APIs from `BugsnagMetadata` interface
[#501](https://github.com/bugsnag/bugsnag-cocoa/pull/501)

Expand Down
5 changes: 5 additions & 0 deletions Source/Bugsnag.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#import "BugsnagClient.h"
#import "BugsnagKeys.h"
#import "BugsnagPlugin.h"
#import "BugsnagHandledState.h"

static BugsnagClient *bsg_g_bugsnag_client = NULL;

Expand All @@ -47,6 +48,10 @@ @interface NSDictionary (BSGKSMerge)
- (NSDictionary *)BSG_mergedInto:(NSDictionary *)dest;
@end

@interface BugsnagEvent ()
@property(readwrite) NSUInteger depth;
@end

@interface BugsnagClient ()
- (void)startListeningForStateChangeNotification:(NSString *_Nonnull)notificationName;
@end
Expand Down
5 changes: 5 additions & 0 deletions Source/BugsnagClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ @interface BugsnagConfiguration ()
@property(readonly, strong, nullable) BugsnagBreadcrumbs *breadcrumbs;
@end

@interface BugsnagEvent ()
@property(readonly, copy, nonnull) NSDictionary *overrides;
@property(readwrite) NSUInteger depth;
@end

@interface BugsnagMetadata ()
- (NSDictionary *_Nonnull)toDictionary;
@property(unsafe_unretained) id<BugsnagMetadataDelegate> _Nullable delegate;
Expand Down
77 changes: 0 additions & 77 deletions Source/BugsnagEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,6 @@ typedef NS_ENUM(NSUInteger, BSGSeverity) {
BSGSeverityInfo,
};

/**
* Convert a string to a severity value
*
* @param severity Intended severity value, such as info, warning, or error
*
* @return converted severity level or BSGSeverityError if no conversion is
* found
*/
BSGSeverity BSGParseSeverity(NSString *_Nonnull severity);

/**
* Serialize a severity for JSON payloads
*
* @param severity a severity
*
* @return the equivalent string value
*/
NSString *_Nonnull BSGFormatSeverity(BSGSeverity severity);

@interface BugsnagEvent : NSObject

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -88,43 +69,12 @@ initWithErrorName:(NSString *_Nonnull)name
handledState:(BugsnagHandledState *_Nonnull)handledState
session:(BugsnagSession *_Nullable)session;

// -----------------------------------------------------------------------------
// MARK: - Misc. Methods
// -----------------------------------------------------------------------------

/**
* Serialize a crash report as a JSON payload
*
* @param data top level report data, may need to be modified based on
* environment
*
* @return a crash report
*/
- (NSDictionary *_Nonnull)serializableValueWithTopLevelData:
(NSMutableDictionary *_Nonnull)data
__deprecated_msg("Use toJson: instead.");

- (NSDictionary *_Nonnull)toJson;

/**
* Whether this report should be sent, based on release stage information
* cached at crash time and within the application currently
*
* @return YES if the report should be sent
*/
- (BOOL)shouldBeSent;

/**
* Prepend a custom stacktrace with a provided type to the crash report
*/
- (void)attachCustomStacktrace:(NSArray *_Nonnull)frames
withType:(NSString *_Nonnull)type;

/**
* Returns the enhanced error message for the thread, or nil if none exists.
*/
- (NSString *_Nullable)enhancedErrorMessageForThread:(NSDictionary *_Nullable)thread __deprecated;

// -----------------------------------------------------------------------------
// MARK: - Metadata
// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -189,10 +139,6 @@ __deprecated_msg("Use toJson: instead.");
// MARK: - Properties
// -----------------------------------------------------------------------------

/**
* The release stages used to notify at the time this report is captured
*/
@property(readwrite, copy, nullable) NSArray *notifyReleaseStages;
/**
* A loose representation of what was happening in the application at the time
* of the event
Expand Down Expand Up @@ -227,31 +173,13 @@ __deprecated_msg("Use toJson: instead.");
* generates a section on bugsnag, displaying key/value pairs
*/
@property(readwrite, copy, nonnull) NSDictionary *metadata;
/**
* The event state (whether the error is handled/unhandled)
*/
@property(readonly, nonnull) BugsnagHandledState *handledState;

/**
* A per-event override for the apiKey.
* - Reads default to the BugsnagConfiguration apiKey value unless explicitly set.
* - Writes are not persisted to BugsnagConfiguration.
*/
@property(readwrite, copy, nonnull) NSString *apiKey;

/**
* Property overrides
*/
@property(readonly, copy, nonnull) NSDictionary *overrides;
/**
* Number of frames to discard at the top of the generated stacktrace.
* Stacktraces from raised exceptions are unaffected.
*/
@property(readwrite) NSUInteger depth;
/**
* Raw error data
*/
@property(readwrite, copy, nullable) NSDictionary *error;
/**
* Device information such as OS name and version
*/
Expand All @@ -269,9 +197,4 @@ __deprecated_msg("Use toJson: instead.");
*/
@property(readwrite, copy, nullable) NSDictionary *appState;

/**
* If YES, a complete report was not able to be obtained at generation time
*/
@property (readonly, nonatomic, getter=isIncomplete) BOOL incomplete;

@end
64 changes: 35 additions & 29 deletions Source/BugsnagEvent.m
Original file line number Diff line number Diff line change
Expand Up @@ -184,25 +184,6 @@ id BSGLoadConfigValue(NSDictionary *report, NSString *valueName) {
?: BSGLoadConfigValue(report, @"releaseStage");
}

BSGSeverity BSGParseSeverity(NSString *severity) {
if ([severity isEqualToString:BSGKeyInfo])
return BSGSeverityInfo;
else if ([severity isEqualToString:BSGKeyWarning])
return BSGSeverityWarning;
return BSGSeverityError;
}

NSString *BSGFormatSeverity(BSGSeverity severity) {
switch (severity) {
case BSGSeverityInfo:
return BSGKeyInfo;
case BSGSeverityError:
return BSGKeyError;
case BSGSeverityWarning:
return BSGKeyWarning;
}
}

NSDictionary *BSGParseCustomException(NSDictionary *report,
NSString *errorClass, NSString *message) {
id frames =
Expand Down Expand Up @@ -267,7 +248,41 @@ @interface BugsnagEvent ()
@property(nonatomic, readwrite, copy, nullable) NSDictionary *customException;
@property(nonatomic, strong) BugsnagSession *session;

@property (nonatomic, readwrite, getter=isIncomplete) BOOL incomplete;
/**
* The event state (whether the error is handled/unhandled)
*/
@property(readonly, nonnull) BugsnagHandledState *handledState;

- (NSDictionary *_Nonnull)toJson;

/**
* Whether this report should be sent, based on release stage information
* cached at crash time and within the application currently
*
* @return YES if the report should be sent
*/
- (BOOL)shouldBeSent;

/**
* The release stages used to notify at the time this report is captured
*/
@property(readwrite, copy, nullable) NSArray *notifyReleaseStages;

/**
* Property overrides
*/
@property(readonly, copy, nonnull) NSDictionary *overrides;

/**
* Number of frames to discard at the top of the generated stacktrace.
* Stacktraces from raised exceptions are unaffected.
*/
@property(readwrite) NSUInteger depth;

/**
* Raw error data
*/
@property(readwrite, copy, nullable) NSDictionary *error;
@end

@implementation BugsnagEvent
Expand Down Expand Up @@ -610,11 +625,6 @@ - (void)setOverrideProperty:(NSString *)key value:(id)value {

}

- (NSDictionary *)serializableValueWithTopLevelData:
(NSMutableDictionary *)data {
return [self toJson];
}

- (NSDictionary *)toJson {
NSMutableDictionary *event = [NSMutableDictionary dictionary];
NSMutableDictionary *metadata = [[self metadata] mutableCopy];
Expand Down Expand Up @@ -769,10 +779,6 @@ - (void)serialiseThread:(NSMutableArray *)bugsnagThreads
BSGArrayAddSafeObject(bugsnagThreads, threadDict);
}

- (NSString *_Nullable)enhancedErrorMessageForThread:(NSDictionary *_Nullable)thread {
return [self errorMessage];
}

@end

@implementation RegisterErrorData
Expand Down
19 changes: 19 additions & 0 deletions Source/BugsnagHandledState.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,25 @@ typedef NS_ENUM(NSUInteger, SeverityReasonType) {
LikelyOutOfMemory,
};

/**
* Convert a string to a severity value
*
* @param severity Intended severity value, such as info, warning, or error
*
* @return converted severity level or BSGSeverityError if no conversion is
* found
*/
BSGSeverity BSGParseSeverity(NSString *severity);

/**
* Serialize a severity for JSON payloads
*
* @param severity a severity
*
* @return the equivalent string value
*/
NSString *BSGFormatSeverity(BSGSeverity severity);

@interface BugsnagHandledState : NSObject

@property(nonatomic, readonly) BOOL unhandled;
Expand Down
20 changes: 20 additions & 0 deletions Source/BugsnagHandledState.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@
//

#import "BugsnagHandledState.h"
#import "BugsnagKeys.h"

BSGSeverity BSGParseSeverity(NSString *severity) {
if ([severity isEqualToString:BSGKeyInfo])
return BSGSeverityInfo;
else if ([severity isEqualToString:BSGKeyWarning])
return BSGSeverityWarning;
return BSGSeverityError;
}

NSString *BSGFormatSeverity(BSGSeverity severity) {
switch (severity) {
case BSGSeverityInfo:
return BSGKeyInfo;
case BSGSeverityError:
return BSGKeyError;
case BSGSeverityWarning:
return BSGKeyWarning;
}
}

static NSString *const kUnhandled = @"unhandled";
static NSString *const kSeverityReasonType = @"severityReasonType";
Expand Down
5 changes: 5 additions & 0 deletions Source/BugsnagSink.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ @interface Bugsnag ()
+ (BugsnagClient *)client;
@end

@interface BugsnagEvent ()
- (NSDictionary *_Nonnull)toJson;
- (BOOL)shouldBeSent;
@end

@interface BugsnagConfiguration ()
@property(nonatomic, readwrite, strong) NSMutableArray *onSendBlocks;
- (NSDictionary *_Nonnull)errorApiHeaders;
Expand Down
6 changes: 6 additions & 0 deletions Tests/BugsnagEventTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ @interface Bugsnag ()
+ (BugsnagConfiguration *)configuration;
@end

@interface BugsnagEvent ()
- (NSDictionary *_Nonnull)toJson;
- (BOOL)shouldBeSent;
@property(readwrite) NSUInteger depth;
@end

@interface BugsnagMetadata ()
- (NSDictionary *_Nonnull)toDictionary;
@end
Expand Down
17 changes: 17 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,20 @@ of the removed `addAttribute`:
- BugsnagCrashReport.addAttribute(_:withValue:toTabWithName:)
+ BugsnagEvent.addMetadata(sectionName:key:value:)
```

#### Removals

```diff
- BSGParseSeverity
- BSGFormatSeverity
- [event serializableValueWithTopLevelData:]
- [event shouldBeSent:]
- [event toJson:]
- [event enhancedErrorMessageForThread:]
- event.notifyReleaseStages
- event.handledState
- event.overrides
- event.depth
- event.error
- event.isIncomplete
```
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class HandledErrorOverrideScenario: Scenario {
Bugsnag.notifyError(error) { report in
report.errorMessage = "Foo"
report.errorClass = "Bar"
report.depth += 2
var depth: Int = report.value(forKey: "depth") as! Int
report.setValue(depth + 2, forKey: "depth")
report.metadata["account"] = [
"items": [400,200]
]
Expand Down
7 changes: 7 additions & 0 deletions iOS/BugsnagTests/BugsnagEventFromKSCrashReportTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ @interface BugsnagEventFromKSCrashReportTest : XCTestCase
@property BugsnagEvent *report;
@end

@interface BugsnagEvent ()
- (NSDictionary *_Nonnull)toJson;
- (BOOL)shouldBeSent;
@property(readwrite, copy, nullable) NSArray *notifyReleaseStages;
@property(readwrite) NSUInteger depth;
@end

@implementation BugsnagEventFromKSCrashReportTest

- (void)setUp {
Expand Down