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

Commit

Permalink
[iOS] report exception when native render error
Browse files Browse the repository at this point in the history
  • Loading branch information
jianhan-he committed Apr 30, 2019
1 parent b6f0175 commit 9c8ea85
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 21 deletions.
21 changes: 16 additions & 5 deletions ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ - (void)registerGlobalFunctions
});
}
else {
WXLogError(@"No data render handler found!");
WXSDKInstance *instance = [WXSDKManager instanceForID:instanceId];
WXSDKErrCode errorCode = WX_ERR_EAGLE_RENDER;
NSError *error = [NSError errorWithDomain:WX_ERROR_DOMAIN code:errorCode userInfo:@{@"message":@"No data render handler found!"}];
instance.onFailed(error);
}
return 0;
}];
Expand Down Expand Up @@ -426,7 +429,9 @@ - (void)createInstance:(NSString *)instanceIdString
});
}
else {
WXLogError(@"No data render handler found!");
WXSDKErrCode errorCode = WX_ERR_EAGLE_RENDER;
NSError *error = [NSError errorWithDomain:WX_ERROR_DOMAIN code:errorCode userInfo:@{@"message":@"No data render handler found!"}];
sdkInstance.onFailed(error);
}
WX_MONITOR_INSTANCE_PERF_END(WXPTJSCreateInstance, [WXSDKManager instanceForID:instanceIdString]);
[sdkInstance.apmInstance onStage:KEY_PAGE_STAGES_LOAD_BUNDLE_END];
Expand Down Expand Up @@ -599,7 +604,9 @@ - (void)createInstance:(NSString *)instanceIdString
});
}
else {
WXLogError(@"No data render handler found!");
WXSDKErrCode errorCode = WX_ERR_EAGLE_RENDER;
NSError *error = [NSError errorWithDomain:WX_ERROR_DOMAIN code:errorCode userInfo:@{@"message":@"No data render handler found!"}];
sdkInstance.onFailed(error);
}
WX_MONITOR_INSTANCE_PERF_END(WXPTJSCreateInstance, [WXSDKManager instanceForID:instanceIdString]);
[sdkInstance.apmInstance onStage:KEY_PAGE_STAGES_LOAD_BUNDLE_END];
Expand Down Expand Up @@ -732,7 +739,9 @@ - (void)destroyInstance:(NSString *)instance
});
}
else {
WXLogError(@"No data render handler found!");
WXSDKErrCode errorCode = WX_ERR_EAGLE_RENDER;
NSError *error = [NSError errorWithDomain:WX_ERROR_DOMAIN code:errorCode userInfo:@{@"message":@"No data render handler found!"}];
sdkInstance.onFailed(error);
}
} else {
[self callJSMethod:@"destroyInstance" args:@[instance]];
Expand All @@ -757,7 +766,9 @@ - (void)refreshInstance:(NSString *)instance
WXSDKInstance *sdkInstance = [WXSDKManager instanceForID:instance];
if (sdkInstance.dataRender) {
if (!_dataRenderHandler) {
WXLogError(@"No data render handler found!");
WXSDKErrCode errorCode = WX_ERR_EAGLE_RENDER;
NSError *error = [NSError errorWithDomain:WX_ERROR_DOMAIN code:errorCode userInfo:@{@"message":@"No data render handler found!"}];
sdkInstance.onFailed(error);
return;
}
WXPerformBlockOnComponentThread(^{
Expand Down
8 changes: 4 additions & 4 deletions ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ static void MergeBorderWidthValues(NSMutableDictionary* dict,
if (!instance) {
break;
}
WXSDKErrCode errorCode = WX_KEY_EXCEPTION_DEGRADE;
WXSDKErrCode errorCode = WX_ERR_JS_EXECUTE;
BOOL is_render_failed = NO;
if (func && strcmp(func, "createInstance") == 0) {
errorCode = WX_KEY_EXCEPTION_EMPTY_SCREEN_JS;
if (func && (strcmp(func, "CreatePageWithContent") == 0 || strcmp(func, "UpdateComponentData") == 0)) {
errorCode = WX_ERR_EAGLE_RENDER;
WXComponentManager *manager = instance.componentManager;
if (manager.isValid) {
NSError *error = [NSError errorWithDomain:WX_ERROR_DOMAIN code:errorCode userInfo:@{@"message":[NSString stringWithUTF8String:exception]}];
NSError *error = [NSError errorWithDomain:WX_ERROR_DOMAIN code:errorCode userInfo:@{@"message":[NSString stringWithUTF8String:exception], @"exception function:":@(func)}];
[manager renderFailed:error];
}
is_render_failed = YES;
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 @@ -55,6 +55,7 @@ typedef NS_ENUM(int, WXSDKErrCode)
WX_ERR_RENDER_REMOVEEVENT = -2107,
WX_ERR_RENDER_SCROLLTOELEMENT = -2110,
WX_ERR_RENDER_TWICE = -2111,
WX_ERR_EAGLE_RENDER = -2112,
WX_ERR_RENDER_END = -2199,

WX_ERR_DOWNLOAD_START = -2201,
Expand Down
5 changes: 3 additions & 2 deletions ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ extern "C" {

/**
+ * download JS Script
+ * @param scriptUrl : script url
+ * @param instance : instance id
+ * @param scriptUrl : script url
+ **/
- (void)DownloadJS:(NSURL *)scriptUrl completion:(void (^)(NSString *script))complection;
- (void)DownloadJS:(NSString *)instance url:(NSURL *)scriptUrl completion:(void (^)(NSString *script))complection;

/**
* Register JS service Script
Expand Down
29 changes: 22 additions & 7 deletions ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -300,21 +300,32 @@ - (JSValue *)callJSMethodWithResult:(WXCallJSMethod *)method
return value;
}

- (void)DownloadJS:(NSURL *)scriptUrl completion:(void (^)(NSString *script))complection;
- (void)DownloadJS:(NSString*)instance url:(NSURL *)scriptUrl completion:(void (^)(NSString *script))complection;
{
if (!scriptUrl || ![scriptUrl.absoluteString length]) {
complection(nil);
if (complection) {
complection(nil);
}
return;
}
WXResourceRequest* request = [WXResourceRequest requestWithURL:scriptUrl];
WXResourceLoader* jsLoader = [[WXResourceLoader alloc] initWithRequest:request];
jsLoader.onFinished = ^(WXResourceResponse *response, NSData *data) {
NSString* jsString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
complection(jsString);
if (complection) {
complection(jsString);
}
};
jsLoader.onFailed = ^(NSError *loadError) {
WXLogError(@"No js URL found");
complection(nil);
if (complection) {
complection(nil);
}

WXSDKInstance *sdkInstance = [WXSDKManager instanceForID:instance];
NSString *errorMessage = [NSString stringWithFormat:@"Request to %@ occurs an error:%@, info:%@", request.URL, loadError.localizedDescription, loadError.userInfo];
WXSDKErrCode errorCode = WX_KEY_EXCEPTION_JS_DOWNLOAD;
NSError *error = [NSError errorWithDomain:WX_ERROR_DOMAIN code:errorCode userInfo:@{NSLocalizedDescriptionKey:(errorMessage?:@"No message")}];
sdkInstance.onFailed(error);
};

[jsLoader start];
Expand Down Expand Up @@ -424,7 +435,9 @@ - (void)fireEvent:(NSString *)instanceId ref:(NSString *)ref type:(NSString *)ty
});
}
else {
WXLogError(@"No data render handler found!");
WXSDKErrCode errorCode = WX_ERR_EAGLE_RENDER;
NSError *error = [NSError errorWithDomain:WX_ERROR_DOMAIN code:errorCode userInfo:@{@"message":@"No data render handler found!"}];
instance.onFailed(error);
}
return;
}
Expand Down Expand Up @@ -497,7 +510,9 @@ - (void)callBack:(NSString *)instanceId funcId:(NSString *)funcId params:(id)par
});
}
else {
WXLogError(@"No data render handler found!");
WXSDKErrCode errorCode = WX_ERR_EAGLE_RENDER;
NSError *error = [NSError errorWithDomain:WX_ERROR_DOMAIN code:errorCode userInfo:@{@"message":@"No data render handler found!"}];
instance.onFailed(error);
}
}
else {
Expand Down
6 changes: 4 additions & 2 deletions ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ - (void)renderView:(id)source options:(NSDictionary *)options data:(id)data
}

- (void)_downloadAndExecScript:(NSURL *)url {
[[WXSDKManager bridgeMgr] DownloadJS:url completion:^(NSString *script) {
[[WXSDKManager bridgeMgr] DownloadJS:_instanceId url:url completion:^(NSString *script) {
if (!script) {
return;
}
Expand All @@ -287,7 +287,9 @@ - (void)_downloadAndExecScript:(NSURL *)url {
});
}
else {
WXLogError(@"No data render handler found!");
WXSDKErrCode errorCode = WX_ERR_EAGLE_RENDER;
NSError *error = [NSError errorWithDomain:WX_ERROR_DOMAIN code:errorCode userInfo:@{@"message":@"No data render handler found!"}];
self.onFailed(error);
}
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

void DefaultRequestHandler::Send(const char* instance_id, const char* url, Callback callback) {
NSURL* nsURL = [NSURL URLWithString:NSSTRING(url)];
[[WXSDKManager bridgeMgr] DownloadJS:nsURL completion:^(NSString *script) {
[[WXSDKManager bridgeMgr] DownloadJS:@(instance_id) url:nsURL completion:^(NSString *script) {
WXPerformBlockOnBridgeThread(^{
callback([script UTF8String] ? : "");
});
Expand Down

0 comments on commit 9c8ea85

Please sign in to comment.