Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[iOS] jsexception deduplication
Browse files Browse the repository at this point in the history
  • Loading branch information
jianhan-he committed May 9, 2019
1 parent 49a74f0 commit 82886d5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,8 @@ - (void)createInstance:(NSString *)instanceIdString
[self callJSMethod:@"createInstance" args:args];
sdkInstance.instanceJavaScriptContext.javaScriptContext[@"wxExtFuncInfo"] = nil;

[WXExceptionUtils commitCriticalExceptionRT:instanceIdString errCode:[NSString stringWithFormat:@"%d", WX_KEY_EXCEPTION_NO_BUNDLE_TYPE] function:@"createInstance" exception:@"Fatal Error : No bundle type in js bundle head, cause white screen or memory leak!!" extParams:nil];

WX_MONITOR_INSTANCE_PERF_END(WXPTJSCreateInstance, [WXSDKManager instanceForID:instanceIdString]);
}
}
Expand Down Expand Up @@ -724,6 +726,9 @@ - (void)destroyInstance:(NSString *)instance
WXAssertBridgeThread();
WXAssertParam(instance);

//remove this instance exception history
[WXExceptionUtils removeExceptionHistory:instance];

//remove instance from stack
@synchronized(self) {
[self.insStack removeObject:instance];
Expand Down
1 change: 1 addition & 0 deletions ios/sdk/WeexSDK/Sources/Engine/WXSDKError.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ typedef NS_ENUM(int, WXSDKErrCode)
WX_KEY_EXCEPTION_EMPTY_SCREEN_NATIVE = -9701,

WX_KEY_EXCEPTION_TOO_MANY_TIMERS = -9800,
WX_KEY_EXCEPTION_NO_BUNDLE_TYPE = -9801,
};

typedef NS_ENUM (NSInteger,WXSDKErrorType)
Expand Down
3 changes: 2 additions & 1 deletion ios/sdk/WeexSDK/Sources/Engine/WXSDKError.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ +(NSDictionary *) getMap
@(WX_KEY_EXCEPTION_EMPTY_SCREEN_JS):@{ERROR_TYPE:@(WX_RENDER_ERROR),ERROR_GROUP:@(WX_JS)},
@(WX_KEY_EXCEPTION_EMPTY_SCREEN_NATIVE):@{ERROR_TYPE:@(WX_RENDER_ERROR),ERROR_GROUP:@(WX_NATIVE)},

@(WX_KEY_EXCEPTION_TOO_MANY_TIMERS):@{ERROR_TYPE:@(WX_NATIVE_ERROR),ERROR_GROUP:@(WX_NATIVE)}
@(WX_KEY_EXCEPTION_TOO_MANY_TIMERS):@{ERROR_TYPE:@(WX_NATIVE_ERROR),ERROR_GROUP:@(WX_NATIVE)},
@(WX_KEY_EXCEPTION_NO_BUNDLE_TYPE):@{ERROR_TYPE:@(WX_JS_ERROR),ERROR_GROUP:@(WX_JS)}
};
});
return codeMap;
Expand Down
2 changes: 2 additions & 0 deletions ios/sdk/WeexSDK/Sources/Monitor/WXExceptionUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@

+ (void)commitCriticalExceptionRT:(WXJSExceptionInfo*)jsExceptionInfo;

+ (void)removeExceptionHistory:(NSString *)instanceId;

@end

25 changes: 25 additions & 0 deletions ios/sdk/WeexSDK/Sources/Monitor/WXExceptionUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,27 @@

@implementation WXExceptionUtils

static NSMutableDictionary *recordExceptionHistory = nil;

+ (void)commitCriticalExceptionRT:(NSString *)instanceId errCode:(NSString *)errCode function:(NSString *)function exception:(NSString *)exception extParams:(NSDictionary *)extParams{
WXLogError(@"Weex exception errCode: %@ function: %@ message: %@", errCode, function, exception);
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
recordExceptionHistory = [[NSMutableDictionary alloc] init];
});

NSMutableDictionary* extInfo = [[NSMutableDictionary alloc] initWithDictionary:extParams];
WXPerformBlockOnComponentThread(^{
NSString *targetException = exception.length > 200 ? [exception substringWithRange:NSMakeRange(0, 200)] : exception;
NSMutableSet *exceptionSet = [recordExceptionHistory objectForKey:instanceId];
if (!exceptionSet) {
exceptionSet = [[NSMutableSet alloc] init];
[recordExceptionHistory setObject:exceptionSet forKey:instanceId];
} else if ([exceptionSet containsObject:targetException]) {
return;
}
[exceptionSet addObject:targetException];

NSString *bundleUrlCommit = @"BundleUrlDefault";
NSString *instanceIdCommit = @"InstanceIdDefalut";
WXSDKInstance * instance ;
Expand Down Expand Up @@ -123,6 +140,14 @@ + (NSString*) _convertInstanceStageToStr:(WXSDKInstance *)instance
return stageStr;
}

+ (void)removeExceptionHistory:(NSString *)instanceId {
WXPerformBlockOnComponentThread(^{
if (recordExceptionHistory) {
[recordExceptionHistory removeObjectForKey:instanceId];
}
});
}



@end

0 comments on commit 82886d5

Please sign in to comment.