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

Commit

Permalink
[iOS] fix crash when instanceid is nil (#2460)
Browse files Browse the repository at this point in the history
  • Loading branch information
jianhan-he authored and lucky-chen committed May 20, 2019
1 parent da0c68c commit f8ea2c4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 41 deletions.
82 changes: 42 additions & 40 deletions ios/sdk/WeexSDK/Sources/Monitor/WXExceptionUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,56 +43,58 @@ + (void)commitCriticalExceptionRT:(NSString *)instanceId errCode:(NSString *)err

NSMutableDictionary* extInfo = [[NSMutableDictionary alloc] initWithDictionary:extParams];
WXPerformBlockOnComponentThread(^{
NSString *bundleUrlCommit = @"BundleUrlDefault";
NSString *instanceIdCommit = @"InstanceIdDefalut";
WXSDKInstance *instance = nil;
if(![WXUtility isBlankString:instanceId]){
instanceIdCommit = instanceId;
instance = [WXSDKManager instanceForID:instanceId];
}

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

NSString *bundleUrlCommit = @"BundleUrlDefault";
NSString *instanceIdCommit = @"InstanceIdDefalut";
WXSDKInstance * instance ;
if(![WXUtility isBlankString:instanceId]){
instanceIdCommit = instanceId;
instance = [WXSDKManager instanceForID:instanceId];
if(instance){
bundleUrlCommit = instance.pageName?:instance.scriptURL.absoluteString;
if(nil == bundleUrlCommit || [@"" isEqualToString:bundleUrlCommit]){
bundleUrlCommit = @"instanceUnSetPageNameOrUrl";
}

if (instance.containerInfo && instance.containerInfo.count >0) {
[extInfo addEntriesFromDictionary:instance.containerInfo];
}
if (nil != instance.viewController) {
[extInfo setObject:NSStringFromClass(instance.viewController.class)?:@"unKnowVCName" forKey:KEY_PAGE_PROPERTIES_CONTAINER_NAME];
}
[extInfo setObject:[self _convertInstanceStageToStr:instance] forKey:@"wxStageList"];
[extInfo setObject:instance.pageName?:@"unKnowPageNameCaseUnSet" forKey:@"wxBundlePageName"];
NSString* bundleTemplateCommit = @"has recycle";
if (nil != instance.bundleTemplate) {
NSUInteger strLength = instance.bundleTemplate.length;
bundleTemplateCommit = [instance.bundleTemplate substringWithRange:NSMakeRange(0, strLength>300?300:strLength)];
}
[extInfo setObject:bundleTemplateCommit forKey:@"wxTemplateOfBundle"];
[extInfo setObject:[instance.apmInstance templateInfo] forKey:@"templateInfo"];
NSNumber* pageStartTime = [instance.apmInstance.stageDic objectForKey:KEY_PAGE_STAGES_DOWN_BUNDLE_START];
if (nil == pageStartTime) {
pageStartTime = [instance.apmInstance.stageDic objectForKey:KEY_PAGE_STAGES_RENDER_ORGIGIN];
}
if (nil != pageStartTime) {
long useTime = [WXUtility getUnixFixTimeMillis] - pageStartTime.longValue;
[extInfo setObject:@(useTime) forKey:@"wxUseTime"];
}

}else if([instanceIdCommit hasPrefix:@"WX_KEY_EXCEPTION"]){
bundleUrlCommit = instanceId;
if(instance){
bundleUrlCommit = instance.pageName?:instance.scriptURL.absoluteString;
if(nil == bundleUrlCommit || [@"" isEqualToString:bundleUrlCommit]){
bundleUrlCommit = @"instanceUnSetPageNameOrUrl";
}

if (instance.containerInfo && instance.containerInfo.count >0) {
[extInfo addEntriesFromDictionary:instance.containerInfo];
}
if (nil != instance.viewController) {
[extInfo setObject:NSStringFromClass(instance.viewController.class)?:@"unKnowVCName" forKey:KEY_PAGE_PROPERTIES_CONTAINER_NAME];
}
[extInfo setObject:[self _convertInstanceStageToStr:instance] forKey:@"wxStageList"];
[extInfo setObject:instance.pageName?:@"unKnowPageNameCaseUnSet" forKey:@"wxBundlePageName"];
NSString* bundleTemplateCommit = @"has recycle";
if (nil != instance.bundleTemplate) {
NSUInteger strLength = instance.bundleTemplate.length;
bundleTemplateCommit = [instance.bundleTemplate substringWithRange:NSMakeRange(0, strLength>300?300:strLength)];
}
[extInfo setObject:bundleTemplateCommit forKey:@"wxTemplateOfBundle"];
[extInfo setObject:[instance.apmInstance templateInfo] forKey:@"templateInfo"];
NSNumber* pageStartTime = [instance.apmInstance.stageDic objectForKey:KEY_PAGE_STAGES_DOWN_BUNDLE_START];
if (nil == pageStartTime) {
pageStartTime = [instance.apmInstance.stageDic objectForKey:KEY_PAGE_STAGES_RENDER_ORGIGIN];
}
if (nil != pageStartTime) {
long useTime = [WXUtility getUnixFixTimeMillis] - pageStartTime.longValue;
[extInfo setObject:@(useTime) forKey:@"wxUseTime"];
}

}else if([instanceIdCommit hasPrefix:@"WX_KEY_EXCEPTION"]){
bundleUrlCommit = instanceId;
}

WXJSExceptionInfo * jsExceptionInfo = [[WXJSExceptionInfo alloc] initWithInstanceId:instanceIdCommit bundleUrl:bundleUrlCommit errorCode:errCode functionName:function exception:exception userInfo: [extInfo mutableCopy]];

// //record top5 erromsg ,if errorType is not WX_RENDER_ERROR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
*/


#include <core/common/view_utils.h>
#include "core/bridge/platform/core_side_in_platform.h"

#include "core/common/view_utils.h"
#include "base/string_util.h"
#include "base/log_defines.h"
#include "core/config/core_environment.h"
Expand Down

0 comments on commit f8ea2c4

Please sign in to comment.