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.
- package/ios/HeimdallNative.m +86 -76
- package/package.json +1 -1
package/ios/HeimdallNative.m
CHANGED
|
@@ -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/
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
81
|
-
if (
|
|
82
|
-
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
[store deleteAllReports];
|
|
116
|
+
|
|
117
|
+
resolve(parsed);
|
|
108
118
|
} @catch (NSException *exception) {
|
|
109
119
|
resolve(@[]);
|
|
110
120
|
}
|