feat:doric android and iOS's monitor add source parameter when exception
This commit is contained in:
@@ -73,13 +73,7 @@ public class DoricNativeDriver implements IDoricDriver {
|
||||
return AsyncCall.ensureRunInHandler(mJSHandler, new Callable<JSDecoder>() {
|
||||
@Override
|
||||
public JSDecoder call() {
|
||||
try {
|
||||
return doricJSEngine.invokeDoricMethod(method, args);
|
||||
} catch (Exception e) {
|
||||
doricJSEngine.getRegistry().onException(e);
|
||||
doricJSEngine.getRegistry().onLog(Log.ERROR, String.format("invokeDoricMethod(%s,...),error is %s", method, e.getLocalizedMessage()));
|
||||
return new JSDecoder(null);
|
||||
}
|
||||
return doricJSEngine.invokeDoricMethod(method, args);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -97,6 +91,14 @@ public class DoricNativeDriver implements IDoricDriver {
|
||||
}
|
||||
}
|
||||
|
||||
private String sourceWithContextId(String contextId) {
|
||||
DoricContext context = DoricContextManager.getContext(contextId);
|
||||
if (context == null) {
|
||||
return "Unknown:" + contextId;
|
||||
}
|
||||
return context.getSource();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AsyncResult<Boolean> createContext(final String contextId, final String script, final String source) {
|
||||
return AsyncCall.ensureRunInHandler(mJSHandler, new Callable<Boolean>() {
|
||||
@@ -106,7 +108,7 @@ public class DoricNativeDriver implements IDoricDriver {
|
||||
doricJSEngine.prepareContext(contextId, script, source);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
doricJSEngine.getRegistry().onException(e);
|
||||
doricJSEngine.getRegistry().onException(sourceWithContextId(contextId), e);
|
||||
doricJSEngine.getRegistry().onLog(Log.ERROR, String.format("createContext %s error is %s", source, e.getLocalizedMessage()));
|
||||
return false;
|
||||
}
|
||||
@@ -123,7 +125,7 @@ public class DoricNativeDriver implements IDoricDriver {
|
||||
doricJSEngine.destroyContext(contextId);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
doricJSEngine.getRegistry().onException(e);
|
||||
doricJSEngine.getRegistry().onException(sourceWithContextId(contextId), e);
|
||||
doricJSEngine.getRegistry().onLog(Log.ERROR, String.format("destroyContext %s error is %s", contextId, e.getLocalizedMessage()));
|
||||
return false;
|
||||
}
|
||||
|
@@ -145,7 +145,7 @@ public class DoricRegistry {
|
||||
}
|
||||
|
||||
|
||||
public void setEnvironmentVariabel(String key, Object val) {
|
||||
public void setEnvironmentVariable(String key, Object val) {
|
||||
extendedEnvValues.put(key, val);
|
||||
}
|
||||
|
||||
@@ -157,9 +157,9 @@ public class DoricRegistry {
|
||||
this.monitors.add(monitor);
|
||||
}
|
||||
|
||||
public void onException(Exception e) {
|
||||
public void onException(String source, Exception e) {
|
||||
for (IDoricMonitor monitor : this.monitors) {
|
||||
monitor.onException(e);
|
||||
monitor.onException(source, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -24,10 +24,11 @@ public interface IDoricMonitor {
|
||||
/**
|
||||
* Called when native or js exception occurred in doric
|
||||
*
|
||||
* @param e exception which is thrown within doric sdk
|
||||
* @param source Which source file
|
||||
* @param e exception which is thrown within doric sdk
|
||||
* @see com.github.pengfeizhou.jscore.JSRuntimeException
|
||||
*/
|
||||
void onException(Exception e);
|
||||
void onException(String source, Exception e);
|
||||
|
||||
/**
|
||||
* @param type The priority/type of this log message.
|
||||
|
@@ -34,6 +34,8 @@ import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
import pub.doric.Doric;
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.DoricContextManager;
|
||||
import pub.doric.DoricRegistry;
|
||||
import pub.doric.IDoricMonitor;
|
||||
import pub.doric.extension.bridge.DoricBridgeExtension;
|
||||
@@ -130,7 +132,7 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
mDoricRegistry.onException(e);
|
||||
mDoricRegistry.onException("Log", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -154,7 +156,7 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
||||
mDoricJSE.loadJS(packageModuleScript(name, content), "Module://" + name);
|
||||
return new JavaValue(true);
|
||||
} catch (Exception e) {
|
||||
mDoricRegistry.onException(e);
|
||||
mDoricRegistry.onException("Require", e);
|
||||
return new JavaValue(false);
|
||||
}
|
||||
}
|
||||
@@ -168,7 +170,7 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
||||
args[1].number().longValue(),
|
||||
args[2].bool());
|
||||
} catch (Exception e) {
|
||||
mDoricRegistry.onException(e);
|
||||
mDoricRegistry.onException("Timer", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -179,7 +181,7 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
||||
try {
|
||||
mTimerExtension.clearTimer(args[0].number().longValue());
|
||||
} catch (Exception e) {
|
||||
mDoricRegistry.onException(e);
|
||||
mDoricRegistry.onException("Timer", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -187,6 +189,7 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
||||
mDoricJSE.injectGlobalJSFunction(DoricConstant.INJECT_BRIDGE, new JavaFunction() {
|
||||
@Override
|
||||
public JavaValue exec(JSDecoder[] args) {
|
||||
String source = "Unknown";
|
||||
try {
|
||||
String contextId = args[0].string();
|
||||
String module = args[1].string();
|
||||
@@ -195,7 +198,7 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
||||
JSDecoder jsDecoder = args[4];
|
||||
return mDoricBridgeExtension.callNative(contextId, module, method, callbackId, jsDecoder);
|
||||
} catch (Exception e) {
|
||||
mDoricRegistry.onException(e);
|
||||
mDoricRegistry.onException("Bridge", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -209,7 +212,7 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
||||
String libJS = DoricUtils.readAssetFile(DoricConstant.DORIC_BUNDLE_LIB);
|
||||
mDoricJSE.loadJS(packageModuleScript(libName, libJS), "Module://" + libName);
|
||||
} catch (Exception e) {
|
||||
mDoricRegistry.onException(e);
|
||||
mDoricRegistry.onException("Init Environment", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,7 +263,7 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
||||
try {
|
||||
invokeDoricMethod(DoricConstant.DORIC_TIMER_CALLBACK, timerId);
|
||||
} catch (Exception e) {
|
||||
mDoricRegistry.onException(e);
|
||||
mDoricRegistry.onException("Timer", e);
|
||||
mDoricRegistry.onLog(
|
||||
Log.ERROR,
|
||||
String.format("Timer Callback error:%s", e.getLocalizedMessage()));
|
||||
@@ -272,7 +275,8 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onException(Exception e) {
|
||||
public void onException(String source, Exception e) {
|
||||
Log.e(DoricJSEngine.class.getSimpleName(), "In source file: " + source);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
@@ -89,6 +89,24 @@ public class DoricBridgeExtension {
|
||||
}
|
||||
};
|
||||
AsyncResult<JavaValue> asyncResult = context.getDriver().asyncCall(callable, doricMethod.thread());
|
||||
asyncResult.setCallback(new AsyncResult.Callback<JavaValue>() {
|
||||
@Override
|
||||
public void onResult(JavaValue result) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable t) {
|
||||
context.getDriver().getRegistry().onException(
|
||||
context.getSource(),
|
||||
t instanceof Exception ? (Exception) t : new RuntimeException(t));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
|
||||
}
|
||||
});
|
||||
if (asyncResult.hasResult()) {
|
||||
return asyncResult.getResult();
|
||||
}
|
||||
@@ -102,7 +120,7 @@ public class DoricBridgeExtension {
|
||||
try {
|
||||
return DoricUtils.toJavaObject(clz, jsDecoder);
|
||||
} catch (Exception e) {
|
||||
context.getDriver().getRegistry().onException(e);
|
||||
context.getDriver().getRegistry().onException(context.getSource(), e);
|
||||
context.getDriver().getRegistry().onLog(
|
||||
Log.ERROR,
|
||||
String.format("createParam error:%s", e.getLocalizedMessage()));
|
||||
|
@@ -15,9 +15,13 @@
|
||||
*/
|
||||
package pub.doric.extension.bridge;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.async.AsyncResult;
|
||||
import pub.doric.utils.DoricConstant;
|
||||
|
||||
import com.github.pengfeizhou.jscore.JSDecoder;
|
||||
import com.github.pengfeizhou.jscore.JavaValue;
|
||||
|
||||
/**
|
||||
@@ -39,9 +43,26 @@ public class DoricPromise {
|
||||
params[0] = context.getContextId();
|
||||
params[1] = callbackId;
|
||||
System.arraycopy(javaValue, 0, params, 2, javaValue.length);
|
||||
context.getDriver().invokeDoricMethod(
|
||||
DoricConstant.DORIC_BRIDGE_RESOLVE,
|
||||
params);
|
||||
context.getDriver()
|
||||
.invokeDoricMethod(
|
||||
DoricConstant.DORIC_BRIDGE_RESOLVE,
|
||||
params)
|
||||
.setCallback(new AsyncResult.Callback<JSDecoder>() {
|
||||
@Override
|
||||
public void onResult(JSDecoder result) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable t) {
|
||||
context.getDriver().getRegistry().onException(context.getSource(), t instanceof Exception ? (Exception) t : new RuntimeException(t));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void reject(JavaValue... javaValue) {
|
||||
@@ -49,8 +70,25 @@ public class DoricPromise {
|
||||
params[0] = context.getContextId();
|
||||
params[1] = callbackId;
|
||||
System.arraycopy(javaValue, 0, params, 2, javaValue.length);
|
||||
context.getDriver().invokeDoricMethod(
|
||||
DoricConstant.DORIC_BRIDGE_REJECT,
|
||||
params);
|
||||
context.getDriver()
|
||||
.invokeDoricMethod(
|
||||
DoricConstant.DORIC_BRIDGE_REJECT,
|
||||
params)
|
||||
.setCallback(new AsyncResult.Callback<JSDecoder>() {
|
||||
@Override
|
||||
public void onResult(JSDecoder result) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable t) {
|
||||
context.getDriver().getRegistry().onException(context.getSource(), t instanceof Exception ? (Exception) t : new RuntimeException(t));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -78,9 +78,9 @@ public class ShaderPlugin extends DoricJavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onError(Throwable t) {
|
||||
if (t instanceof Exception) {
|
||||
getDoricContext().getDriver().getRegistry().onException((Exception) t);
|
||||
}
|
||||
getDoricContext().getDriver().getRegistry().onException(
|
||||
getDoricContext().getSource(),
|
||||
t instanceof Exception ? (Exception) t : new RuntimeException(t));
|
||||
getDoricContext().getDriver().getRegistry().onLog(
|
||||
Log.ERROR,
|
||||
String.format("Shader.render:error%s", t.getLocalizedMessage()));
|
||||
@@ -92,7 +92,7 @@ public class ShaderPlugin extends DoricJavaPlugin {
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
getDoricContext().getDriver().getRegistry().onException(e);
|
||||
getDoricContext().getDriver().getRegistry().onException(getDoricContext().getSource(), e);
|
||||
getDoricContext().getDriver().getRegistry().onLog(
|
||||
Log.ERROR,
|
||||
String.format("Shader.render:error%s", e.getLocalizedMessage())
|
||||
@@ -173,7 +173,7 @@ public class ShaderPlugin extends DoricJavaPlugin {
|
||||
}
|
||||
}
|
||||
} catch (ArchiveException e) {
|
||||
getDoricContext().getDriver().getRegistry().onException(e);
|
||||
getDoricContext().getDriver().getRegistry().onException(getDoricContext().getSource(), e);
|
||||
}
|
||||
return new JavaValue(true);
|
||||
}
|
||||
|
Reference in New Issue
Block a user