Repository: incubator-weex
Updated Branches:
  refs/heads/master b049f80ee -> 39b4add31


* [Android] Add exception info when there is a JS error during addElementAction.


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/39b4add3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/39b4add3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/39b4add3

Branch: refs/heads/master
Commit: 39b4add31d1d76284b5609a992c1e78576f3b527
Parents: b049f80
Author: YorkShen <shenyua...@gmail.com>
Authored: Mon May 14 12:05:42 2018 +0800
Committer: YorkShen <shenyua...@gmail.com>
Committed: Mon May 14 14:20:31 2018 +0800

----------------------------------------------------------------------
 .../com/taobao/weex/common/WXErrorCode.java     |  2 ++
 .../weex/ui/action/GraphicActionAddElement.java | 29 +++++++++++++++-----
 2 files changed, 24 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/39b4add3/android/sdk/src/main/java/com/taobao/weex/common/WXErrorCode.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/common/WXErrorCode.java 
b/android/sdk/src/main/java/com/taobao/weex/common/WXErrorCode.java
index e18a075..fcc5394 100644
--- a/android/sdk/src/main/java/com/taobao/weex/common/WXErrorCode.java
+++ b/android/sdk/src/main/java/com/taobao/weex/common/WXErrorCode.java
@@ -231,6 +231,8 @@ public enum WXErrorCode {
   WX_RENDER_ERR_JS_CREATE_INSTANCE("-9600", 
"WX_RENDER_ERR_JS_CREATE_INSTANCE",ErrorType.RENDER_ERROR,ErrorGroup.JS),
   WX_RENDER_ERR_JS_RUNTIME("-9601", "WX_RENDER_ERR for js 
error",ErrorType.RENDER_ERROR, ErrorGroup.JS),
   WX_RENDER_ERR_LAYER_OVERFLOW("-9602", "WX_RENDER_ERR_LAYER_OVERFLOW", 
ErrorType.RENDER_ERROR, ErrorGroup.JS),
+  WX_RENDER_ERR_CONTAINER_TYPE("-9611", "WX_RENDER_ERR_CONTAINER_TYPE", 
ErrorType.JS_ERROR,ErrorGroup.JS),
+
 
 
   /**

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/39b4add3/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java
----------------------------------------------------------------------
diff --git 
a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java
 
b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java
index 347b7fa..77bb5e2 100644
--- 
a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java
+++ 
b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java
@@ -23,11 +23,13 @@ import android.support.annotation.RestrictTo.Scope;
 import android.support.annotation.WorkerThread;
 import com.taobao.weex.WXSDKInstance;
 import com.taobao.weex.WXSDKManager;
+import com.taobao.weex.common.WXErrorCode;
 import com.taobao.weex.dom.transition.WXTransition;
 import com.taobao.weex.ui.component.WXComponent;
 import com.taobao.weex.ui.component.WXVContainer;
+import com.taobao.weex.utils.WXExceptionUtils;
 import com.taobao.weex.utils.WXLogUtils;
-
+import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 
@@ -63,13 +65,26 @@ public class GraphicActionAddElement extends 
GraphicActionAbstractAddElement {
       return;
     }
 
-    parent = (WXVContainer) 
WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), 
mParentRef);
-    BasicComponentData basicComponentData = new BasicComponentData(ref, 
mComponentType, mParentRef);
-    child = createComponent(instance, parent, basicComponentData);
-    child.setTransition(WXTransition.fromMap(child.getStyles(), child));
+    try {
+      parent = (WXVContainer) WXSDKManager.getInstance().getWXRenderManager()
+          .getWXComponent(getPageId(), mParentRef);
+      BasicComponentData basicComponentData = new BasicComponentData(ref, 
mComponentType,
+          mParentRef);
+      child = createComponent(instance, parent, basicComponentData);
+      child.setTransition(WXTransition.fromMap(child.getStyles(), child));
 
-    if (child == null || parent == null) {
-      return;
+      if (child == null || parent == null) {
+        return;
+      }
+    }catch (ClassCastException e){
+      WXExceptionUtils.commitCriticalExceptionRT(instance.getInstanceId(),
+          WXErrorCode.WX_RENDER_ERR_CONTAINER_TYPE,
+          "GraphicActionAddElement",
+          String.format(Locale.ENGLISH,"You are trying to add a %s (ref: %s) 
to a %3$s (ref: %4$s), which is illegal as %3$s (ref: %4$s) is not a container",
+              componentType, ref,
+              
WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), 
mParentRef).getComponentType(),
+              parentRef),
+          null);
     }
 
   }

Reply via email to