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

Commit

Permalink
[WEEX-587][iOS] excpetion report fix (#1469)
Browse files Browse the repository at this point in the history
* [iOS] fix empty check logic

* [iOS] report detail info of bundel (pageNmae,stagelist,errorHistory,template)

* [iOS] add apm switch
  • Loading branch information
lucky-chen authored and cxfeng1 committed Aug 23, 2018
1 parent e86c859 commit 7c1f15e
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 49 deletions.
23 changes: 0 additions & 23 deletions ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -1046,9 +1046,6 @@ + (void)mountContextEnvironment:(JSContext*)context
message = [NSString stringWithFormat:@"[WX_KEY_EXCEPTION_WXBRIDGE] [%@:%@:%@] %@\n%@\n%@\n%@\n%@\n%@", exception[@"sourceURL"], exception[@"line"], exception[@"column"], [exception toString], [exception[@"stack"] toObject], instance.scriptURL.absoluteString, instance.callCreateInstanceContext?:@"", instance.createInstanceContextResult?:@"", instance.executeRaxApiResult?:@""];
userInfo = @{@"jsMainBundleStringContentLength":instance.userInfo[@"jsMainBundleStringContentLength"]?:@"",
@"jsMainBundleStringContentMd5":instance.userInfo[@"jsMainBundleStringContentMd5"]?:@""};
if ([self checkEmptyScreen:instance]) {
errorCode = [NSString stringWithFormat:@"%d", WX_KEY_EXCEPTION_EMPTY_SCREEN_JS];
}
}

if (commitException) {
Expand Down Expand Up @@ -1121,24 +1118,4 @@ + (void)handleConsoleOutputWithArgument:(NSArray*)arguments logLevel:(WXLogFlag)
}
}];
}

+ (BOOL) checkEmptyScreen:(WXSDKInstance *) instance
{
if(!instance){
return false;
}
if (!(instance.rootView) ) {
return true;
}
CGRect rootFrame = instance.rootView.frame;

if (rootFrame.size.height <=0 || rootFrame.size.width <=0) {
return true;
}

if (!(instance.rootView.subviews) || instance.rootView.subviews.count <=0) {
return true;
}
return false;
}
@end
3 changes: 2 additions & 1 deletion ios/sdk/WeexSDK/Sources/Engine/WXSDKError.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ typedef NS_ENUM(int, WXSDKErrCode)
WX_KEY_EXCEPTION_ABILITY_DOWN_TOH5 = -9602,
WX_KEY_EXCEPTION_ABILITY_DOWN_ = -9603,

WX_KEY_EXCEPTION_EMPTY_SCREEN_JS = -9700
WX_KEY_EXCEPTION_EMPTY_SCREEN_JS = -9700,
WX_KEY_EXCEPTION_EMPTY_SCREEN_NATIVE = -9701
};

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 @@ -99,7 +99,8 @@ +(NSDictionary *) getMap
@(WX_KEY_EXCEPTION_ABILITY_DOWN_TOH5):@{ERROR_TYPE:@(WX_NATIVE_ERROR),ERROR_GROUP:@(WX_NATIVE)},
@(WX_ERR_JSFRAMEWORK_START):@{ERROR_TYPE:@(WX_NATIVE_ERROR),ERROR_GROUP:@(WX_NATIVE)},
@(WX_KEY_EXCEPTION_ABILITY_DOWN_):@{ERROR_TYPE:@(WX_NATIVE_ERROR),ERROR_GROUP:@(WX_NATIVE)},
@(WX_KEY_EXCEPTION_EMPTY_SCREEN_JS):@{ERROR_TYPE:@(WX_RENDER_ERROR),ERROR_GROUP:@(WX_JS)}
@(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)}
};
});
return codeMap;
Expand Down
5 changes: 5 additions & 0 deletions ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ - (void)createInstance:(NSString *)instance
[self.instanceIdStack insertObject:instance atIndex:0];
}
}
//third team impl...
WXSDKInstance* sdkInstance = [WXSDKManager instanceForID:instance];
if (sdkInstance) {
sdkInstance.apmInstance.isStartRender = YES;
}
__weak typeof(self) weakSelf = self;
WXPerformBlockOnBridgeThread(^(){
[WXTracingManager startTracingWithInstanceId:instance ref:nil className:nil name:WXTExecJS phase:WXTracingBegin functionName:@"createInstance" options:@{@"threadName":WXTJSBridgeThread}];
Expand Down
1 change: 1 addition & 0 deletions ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ - (void)addComponent:(NSDictionary *)componentData toSupercomponent:(NSString *)
WXLogWarning(@"addComponent,superRef from js never exit ! check JS action, supRef:%@",superRef);
return;
}
supercomponent.weexInstance.apmInstance.hasAddView = YES;

[self _recursivelyAddComponent:componentData toSupercomponent:supercomponent atIndex:index appendingInTree:appendingInTree];
}
Expand Down
5 changes: 5 additions & 0 deletions ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ typedef NS_ENUM(NSInteger, WXErrorCode) {//error.code
*/
- (NSURL *)completeURL:(NSString *)url;

/**
* jsbundle str ,may be nil (weak)
*/
- (NSString*) bundleTemplate;

/**
* application performance statistics
*/
Expand Down
7 changes: 7 additions & 0 deletions ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ - (void)renderWithURL:(NSURL *)url options:(NSDictionary *)options data:(id)data
return;
}
[self.apmInstance startRecord:self.instanceId];
self.apmInstance.isStartRender = YES;

self.needValidate = [[WXHandlerFactory handlerForProtocol:@protocol(WXValidateProtocol)] needValidate:url];
WXResourceRequest *request = [WXResourceRequest requestWithURL:url resourceType:WXResourceTypeMainBundle referrer:@"" cachePolicy:NSURLRequestUseProtocolCachePolicy];
Expand All @@ -239,6 +240,11 @@ - (void)renderView:(NSString *)source options:(NSDictionary *)options data:(id)d
[WXTracingManager setBundleJSType:source instanceId:self.instanceId];
}

- (NSString*) bundleTemplate
{
return self.mainBundleString;
}

- (void)_renderWithMainBundleString:(NSString *)mainBundleString
{
if (!self.instanceId) {
Expand All @@ -248,6 +254,7 @@ - (void)_renderWithMainBundleString:(NSString *)mainBundleString

//some case , with out render (url)
[self.apmInstance startRecord:self.instanceId];
self.apmInstance.isStartRender = YES;

self.performance.renderTimeOrigin = CACurrentMediaTime()*1000;
[self.apmInstance onStage:KEY_PAGE_STAGES_RENDER_ORGIGIN];
Expand Down
43 changes: 39 additions & 4 deletions ios/sdk/WeexSDK/Sources/Monitor/WXExceptionUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,38 @@ + (void)commitCriticalExceptionRT:(NSString *)instanceId errCode:(NSString *)err
NSString *bundleUrlCommit = @"BundleUrlDefault";
NSString *instanceIdCommit = @"InstanceIdDefalut";

WXSDKInstance * instance ;
if(![WXUtility isBlankString:instanceId]){
instanceIdCommit = instanceId;
WXSDKInstance * instance = [WXSDKManager instanceForID:instanceId];
instance = [WXSDKManager instanceForID:instanceId];
if(instance){
bundleUrlCommit = instance.pageName?:([instance.scriptURL absoluteString]?:bundleUrlCommit);
NSMutableDictionary* extInfo = [[NSMutableDictionary alloc] initWithDictionary:extParams];
if (instance.containerInfo && instance.containerInfo.count >0) {
NSMutableDictionary* extInfo = [[NSMutableDictionary alloc] initWithDictionary:extParams];
[extInfo addEntriesFromDictionary:instance.containerInfo];
extParams = extInfo;
}
[extInfo setObject:[self _convertInstanceStageToStr:instance] forKey:@"wxStageList"];
[extInfo setObject:instance.pageName?:@"unKnowPageNameCaseUnSet" forKey:@"wxPageName"];
[extInfo setObject:instance.bundleTemplate?:@"has recycle" forKey:@"wxTemplateOfBundle"];
extParams = extInfo;
}else if([instanceIdCommit hasPrefix:@"WX_KEY_EXCEPTION"]){
bundleUrlCommit = instanceId;
}
}

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

//record top5 erromsg ,if errorType is not WX_RENDER_ERROR
NSNumberFormatter *formater = [[NSNumberFormatter alloc] init];
formater.numberStyle = NSNumberFormatterDecimalStyle;
NSNumber *codeNumber = [formater numberFromString:errCode];
if (codeNumber) {
WXSDKErrorType type = [WXSDKErrCodeUtil getErrorTypeByCode:codeNumber.intValue];
if (type != WX_RENDER_ERROR && nil != instance) {
[instance.apmInstance recordErrorMsg:jsExceptionInfo];
}
}

[WXExceptionUtils commitCriticalExceptionRT:jsExceptionInfo];
}

Expand All @@ -64,4 +80,23 @@ + (void)commitCriticalExceptionRT:(WXJSExceptionInfo *)jsExceptionInfo{
}
}

+ (NSString*) _convertInstanceStageToStr:(WXSDKInstance *)instance
{
if (nil == instance || !instance.apmInstance.isOpenApm) {
return @"";
}
NSDictionary<NSString*,NSNumber*>* stageDic = instance.apmInstance.stageDic;
if (!stageDic || stageDic.count <=0 ) {
return @"emptyStageRecord";
}
NSString* stageStr = @"";
for (NSString* key in stageDic) {
NSNumber* time = [stageDic objectForKey:key];
stageStr = [stageStr stringByAppendingFormat:@"%@ -> %@:%@",stageStr,key,time];
}
return stageStr;
}



@end
12 changes: 10 additions & 2 deletions ios/sdk/WeexSDK/Sources/Performance/WXApmForInstance.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import <Foundation/Foundation.h>
#import "WXJSExceptionInfo.h"

#pragma mark - const static string

Expand Down Expand Up @@ -76,8 +77,12 @@ extern NSString* const VALUE_ERROR_CODE_DEFAULT;

@interface WXApmForInstance : NSObject

@property (nonatomic, assign) bool isFSEnd;
@property (nonatomic, assign) bool isStartRecord;
@property (nonatomic, assign) BOOL isFSEnd;
@property (nonatomic,assign) BOOL isOpenApm;
@property (nonatomic, assign) BOOL isStartRecord;
@property (nonatomic, assign) BOOL hasAddView;
@property (nonatomic, assign) BOOL isDegrade;
@property (nonatomic, assign) BOOL isStartRender;

#pragma mark - basic method

Expand Down Expand Up @@ -106,4 +111,7 @@ extern NSString* const VALUE_ERROR_CODE_DEFAULT;
- (void) actionImgLoad;
- (void) actionImgLoadResult:(bool)succeed withErrorCode:(NSString*)errorCode;

#pragma mark record top5 errorMsg
- (void) recordErrorMsg:(WXJSExceptionInfo *)exception;
- (NSDictionary<NSString*,NSNumber*>*) stageDic;
@end
Loading

0 comments on commit 7c1f15e

Please sign in to comment.