heimdall-react-native 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,8 @@
3
3
  #import <sys/utsname.h>
4
4
  #import <mach/mach.h>
5
5
  #import <KSCrash/KSCrash.h>
6
- #import <KSCrash/KSCrashReportFilterBasic.h>
6
+ #import <KSCrash/KSCrashConfiguration.h>
7
+ #import <KSCrash/KSCrashReport.h>
7
8
 
8
9
  @implementation HeimdallNative
9
10
 
@@ -16,9 +17,14 @@ RCT_EXPORT_MODULE();
16
17
  RCT_EXPORT_METHOD(startNativeHandler) {
17
18
  dispatch_async(dispatch_get_main_queue(), ^{
18
19
  @try {
19
- KSCrash *handler = [KSCrash sharedInstance];
20
- [handler install];
21
- RCTLogInfo(@"[Heimdall] Native crash handler installed");
20
+ KSCrashConfiguration *config = [[KSCrashConfiguration alloc] init];
21
+ NSError *error = nil;
22
+ BOOL success = [[KSCrash sharedInstance] installWithConfiguration:config error:&error];
23
+ if (success) {
24
+ RCTLogInfo(@"[Heimdall] Native crash handler installed");
25
+ } else {
26
+ RCTLogWarn(@"[Heimdall] Failed to install native crash handler: %@", error.localizedDescription);
27
+ }
22
28
  } @catch (NSException *exception) {
23
29
  RCTLogWarn(@"[Heimdall] Failed to install native crash handler: %@", exception.reason);
24
30
  }
@@ -28,83 +34,87 @@ RCT_EXPORT_METHOD(startNativeHandler) {
28
34
  RCT_EXPORT_METHOD(getPendingCrashReports:(RCTPromiseResolveBlock)resolve
29
35
  rejecter:(RCTPromiseRejectBlock)reject) {
30
36
  @try {
31
- KSCrash *handler = [KSCrash sharedInstance];
32
-
33
- [handler reportCount];
34
-
35
- [handler allReports:^(NSArray *reports) {
36
- if (!reports || reports.count == 0) {
37
- resolve(@[]);
38
- return;
39
- }
40
-
41
- NSMutableArray *parsed = [NSMutableArray array];
42
-
43
- for (NSDictionary *report in reports) {
44
- @try {
45
- NSDictionary *crash = report[@"crash"];
46
- NSDictionary *error = crash[@"error"];
47
- NSArray *threads = crash[@"threads"];
48
-
49
- NSString *type = error[@"type"] ?: @"Unknown";
50
- NSString *reason = error[@"reason"] ?: @"Native crash";
51
-
52
- if ([type isEqualToString:@"nsexception"]) {
53
- NSDictionary *nsException = error[@"nsexception"];
54
- if (nsException) {
55
- type = nsException[@"name"] ?: type;
56
- reason = nsException[@"reason"] ?: reason;
57
- }
58
- } else if ([type isEqualToString:@"signal"]) {
59
- NSDictionary *signal = error[@"signal"];
60
- if (signal) {
61
- type = signal[@"name"] ?: type;
62
- }
63
- } else if ([type isEqualToString:@"mach"]) {
64
- NSDictionary *mach = error[@"mach"];
65
- if (mach) {
66
- type = mach[@"exception_name"] ?: type;
67
- }
37
+ KSCrashReportStore *store = [[KSCrash sharedInstance] reportStore];
38
+ if (!store) {
39
+ resolve(@[]);
40
+ return;
41
+ }
42
+
43
+ NSArray *reportIDs = [store reportIDs];
44
+ if (!reportIDs || reportIDs.count == 0) {
45
+ resolve(@[]);
46
+ return;
47
+ }
48
+
49
+ NSMutableArray *parsed = [NSMutableArray array];
50
+
51
+ for (NSNumber *reportID in reportIDs) {
52
+ @try {
53
+ KSCrashReportDictionary *reportObj = [store reportForID:[reportID longLongValue]];
54
+ if (!reportObj) continue;
55
+ NSDictionary *report = reportObj.value;
56
+
57
+ NSDictionary *crash = report[@"crash"];
58
+ NSDictionary *error = crash[@"error"];
59
+ NSArray *threads = crash[@"threads"];
60
+
61
+ NSString *type = error[@"type"] ?: @"Unknown";
62
+ NSString *reason = error[@"reason"] ?: @"Native crash";
63
+
64
+ if ([type isEqualToString:@"nsexception"]) {
65
+ NSDictionary *nsException = error[@"nsexception"];
66
+ if (nsException) {
67
+ type = nsException[@"name"] ?: type;
68
+ reason = nsException[@"reason"] ?: reason;
68
69
  }
69
-
70
- NSMutableArray *stacktrace = [NSMutableArray array];
71
-
72
- NSDictionary *crashedThread = nil;
73
- for (NSDictionary *thread in threads) {
74
- if ([thread[@"crashed"] boolValue]) {
75
- crashedThread = thread;
76
- break;
77
- }
70
+ } else if ([type isEqualToString:@"signal"]) {
71
+ NSDictionary *signal = error[@"signal"];
72
+ if (signal) {
73
+ type = signal[@"name"] ?: type;
78
74
  }
79
-
80
- NSArray *backtrace = crashedThread[@"backtrace"][@"contents"];
81
- if (backtrace) {
82
- for (NSDictionary *frame in backtrace) {
83
- [stacktrace addObject:@{
84
- @"filename": frame[@"object_name"] ?: @"<unknown>",
85
- @"function": frame[@"symbol_name"] ?: @"<unknown>",
86
- @"lineno": frame[@"instruction_addr"] ?: @0,
87
- @"colno": @0,
88
- @"in_app": @(![frame[@"object_name"] hasPrefix:@"/usr"])
89
- }];
90
- }
75
+ } else if ([type isEqualToString:@"mach"]) {
76
+ NSDictionary *mach = error[@"mach"];
77
+ if (mach) {
78
+ type = mach[@"exception_name"] ?: type;
91
79
  }
92
-
93
- [parsed addObject:@{
94
- @"type": type,
95
- @"value": reason,
96
- @"stacktrace": stacktrace
97
- }];
98
- } @catch (NSException *exception) {
99
- RCTLogWarn(@"[Heimdall] Failed to parse crash report: %@", exception.reason);
100
80
  }
81
+
82
+ NSMutableArray *stacktrace = [NSMutableArray array];
83
+
84
+ NSDictionary *crashedThread = nil;
85
+ for (NSDictionary *thread in threads) {
86
+ if ([thread[@"crashed"] boolValue]) {
87
+ crashedThread = thread;
88
+ break;
89
+ }
90
+ }
91
+
92
+ NSArray *backtrace = crashedThread[@"backtrace"][@"contents"];
93
+ if (backtrace) {
94
+ for (NSDictionary *frame in backtrace) {
95
+ [stacktrace addObject:@{
96
+ @"filename": frame[@"object_name"] ?: @"<unknown>",
97
+ @"function": frame[@"symbol_name"] ?: @"<unknown>",
98
+ @"lineno": frame[@"instruction_addr"] ?: @0,
99
+ @"colno": @0,
100
+ @"in_app": @(![frame[@"object_name"] hasPrefix:@"/usr"])
101
+ }];
102
+ }
103
+ }
104
+
105
+ [parsed addObject:@{
106
+ @"type": type,
107
+ @"value": reason,
108
+ @"stacktrace": stacktrace
109
+ }];
110
+ } @catch (NSException *exception) {
111
+ RCTLogWarn(@"[Heimdall] Failed to parse crash report: %@", exception.reason);
101
112
  }
102
-
103
- // Delete the reports after reading
104
- [handler deleteAllReports];
105
-
106
- resolve(parsed);
107
- }];
113
+ }
114
+
115
+ [store deleteAllReports];
116
+
117
+ resolve(parsed);
108
118
  } @catch (NSException *exception) {
109
119
  resolve(@[]);
110
120
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "heimdall-react-native",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Lightweight crash tracking SDK for React Native iOS apps",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",