feat:doric android and iOS's monitor add source parameter when exception
This commit is contained in:
@@ -54,6 +54,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
- (void)disconnectDevKit;
|
||||
|
||||
- (void)ensureSyncInMainQueue:(dispatch_block_t)block;
|
||||
|
||||
- (NSString *)aliasWithContextId:(NSString *)contextId;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
@@ -24,6 +24,7 @@
|
||||
#import "DoricJSEngine.h"
|
||||
#import "DoricConstant.h"
|
||||
#import "DoricWSClient.h"
|
||||
#import "DoricContextManager.h"
|
||||
|
||||
@interface DoricDriver ()
|
||||
@property(nonatomic, strong) DoricJSEngine *jsExecutor;
|
||||
@@ -62,6 +63,10 @@ + (instancetype)instance {
|
||||
return ret;
|
||||
}
|
||||
|
||||
- (NSString *)aliasWithContextId:(NSString *)contextId {
|
||||
return [[DoricContextManager instance] getContext:contextId].source;
|
||||
}
|
||||
|
||||
- (DoricAsyncResult<JSValue *> *)invokeDoricMethod:(NSString *)method arguments:(va_list)args {
|
||||
DoricAsyncResult *ret = [[DoricAsyncResult alloc] init];
|
||||
NSMutableArray *array = [[NSMutableArray alloc] init];
|
||||
@@ -78,7 +83,6 @@ + (instancetype)instance {
|
||||
[ret setupResult:jsValue];
|
||||
} @catch (NSException *exception) {
|
||||
[ret setupError:exception];
|
||||
[self.jsExecutor.registry onException:exception];
|
||||
}
|
||||
});
|
||||
return ret;
|
||||
@@ -111,7 +115,7 @@ - (DoricAsyncResult *)invokeContextEntity:(NSString *)contextId method:(NSString
|
||||
[ret setupResult:jsValue];
|
||||
} @catch (NSException *exception) {
|
||||
[ret setupError:exception];
|
||||
[self.jsExecutor.registry onException:exception];
|
||||
[self.jsExecutor.registry onException:exception source:[self aliasWithContextId:contextId]];
|
||||
}
|
||||
});
|
||||
return ret;
|
||||
@@ -134,7 +138,7 @@ - (DoricAsyncResult *)invokeContextEntity:(NSString *)contextId method:(NSString
|
||||
[ret setupResult:jsValue];
|
||||
} @catch (NSException *exception) {
|
||||
[ret setupError:exception];
|
||||
[self.jsExecutor.registry onException:exception];
|
||||
[self.jsExecutor.registry onException:exception source:[self aliasWithContextId:contextId]];
|
||||
}
|
||||
});
|
||||
return ret;
|
||||
@@ -151,7 +155,7 @@ - (DoricAsyncResult *)createContext:(NSString *)contextId script:(NSString *)scr
|
||||
[ret setupResult:@YES];
|
||||
} @catch (NSException *exception) {
|
||||
[ret setupError:exception];
|
||||
[self.jsExecutor.registry onException:exception];
|
||||
[self.jsExecutor.registry onException:exception source:source];
|
||||
}
|
||||
});
|
||||
return ret;
|
||||
@@ -168,7 +172,7 @@ - (DoricAsyncResult *)destroyContext:(NSString *)contextId {
|
||||
[ret setupResult:@YES];
|
||||
} @catch (NSException *exception) {
|
||||
[ret setupError:exception];
|
||||
[self.jsExecutor.registry onException:exception];
|
||||
[self.jsExecutor.registry onException:exception source:[self aliasWithContextId:contextId]];
|
||||
}
|
||||
});
|
||||
return ret;
|
||||
|
@@ -11,7 +11,17 @@ typedef NS_ENUM(NSInteger, DoricLogType) {
|
||||
};
|
||||
|
||||
@protocol DoricMonitorProtocol <NSObject>
|
||||
- (void)onException:(NSException *)exception;
|
||||
/**
|
||||
* Called when native or js exception occurred in doric
|
||||
*
|
||||
* @param source Which source file
|
||||
* @param e exception which is thrown within doric sdk
|
||||
*/
|
||||
- (void)onException:(NSException *)exception source:(NSString *)source;
|
||||
|
||||
/**
|
||||
* @param type The priority/type of this log message.
|
||||
* @param message The message you would like logged.
|
||||
*/
|
||||
- (void)onLog:(DoricLogType)type message:(NSString *)message;
|
||||
@end
|
@@ -80,8 +80,8 @@ @interface DoricDefaultMonitor : NSObject <DoricMonitorProtocol>
|
||||
@end
|
||||
|
||||
@implementation DoricDefaultMonitor
|
||||
- (void)onException:(NSException *)exception {
|
||||
DoricLog(@"DefaultMonitor - onException - %@", exception.reason);
|
||||
- (void)onException:(NSException *)exception source:(NSString *)source {
|
||||
DoricLog(@"DefaultMonitor - source: %@- onException - %@", source, exception.reason);
|
||||
}
|
||||
|
||||
- (void)onLog:(DoricLogType)type message:(NSString *)message {
|
||||
@@ -187,9 +187,9 @@ - (void)registerMonitor:(id <DoricMonitorProtocol>)monitor {
|
||||
[self.monitors addObject:monitor];
|
||||
}
|
||||
|
||||
- (void)onException:(NSException *)exception {
|
||||
- (void)onException:(NSException *)exception source:(NSString *)source {
|
||||
for (id <DoricMonitorProtocol> monitor in self.monitors) {
|
||||
[monitor onException:exception];
|
||||
[monitor onException:exception source:source];
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -139,7 +139,7 @@ - (void)initDoricEnvironment {
|
||||
[self.jsExecutor loadJSScript:[self packageModuleScript:DORIC_MODULE_LIB content:jsContent]
|
||||
source:[@"Module://" stringByAppendingString:DORIC_MODULE_LIB]];
|
||||
} @catch (NSException *exception) {
|
||||
[self.registry onException:exception];
|
||||
[self.registry onException:exception source:@"InitEnvironment"];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ - (void)callbackTimer:(NSTimer *)timer {
|
||||
@try {
|
||||
[self invokeDoricMethod:DORIC_TIMER_CALLBACK, timerId, nil];
|
||||
} @catch (NSException *exception) {
|
||||
[self.registry onException:exception];
|
||||
[self.registry onException:exception source:@"Timer"];
|
||||
[self.registry onLog:DoricLogTypeError
|
||||
message:[NSString stringWithFormat:@"Timer Callback error:%@", exception.reason]];
|
||||
}
|
||||
|
@@ -87,7 +87,7 @@ - (id)findClass:(Class)clz target:(id)target context:(DoricContext *)context met
|
||||
[invocation invoke];
|
||||
} @catch (NSException *exception) {
|
||||
DoricLog(@"CallNative Error:%@", exception.reason);
|
||||
[context.driver.registry onException:exception];
|
||||
[context.driver.registry onException:exception source:context.source];
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -40,10 +40,20 @@ - (instancetype)initWithContext:(DoricContext *)context callbackId:(NSString *)c
|
||||
}
|
||||
|
||||
- (void)resolve:(id)result {
|
||||
[self.context.driver invokeDoricMethod:DORIC_BRIDGE_RESOLVE, self.context.contextId, self.callbackId, result, nil];
|
||||
[[self.context.driver invokeDoricMethod:DORIC_BRIDGE_RESOLVE, self.context.contextId, self.callbackId, result, nil]
|
||||
setExceptionCallback:^(NSException *e) {
|
||||
[self.context.driver.registry
|
||||
onException:e
|
||||
source:self.context.source];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)reject:(id)result {
|
||||
[self.context.driver invokeDoricMethod:DORIC_BRIDGE_REJECT, self.context.contextId, self.callbackId, result, nil];
|
||||
[[self.context.driver invokeDoricMethod:DORIC_BRIDGE_REJECT, self.context.contextId, self.callbackId, result, nil]
|
||||
setExceptionCallback:^(NSException *e) {
|
||||
[self.context.driver.registry
|
||||
onException:e
|
||||
source:self.context.source];
|
||||
}];
|
||||
}
|
||||
@end
|
||||
|
@@ -108,7 +108,7 @@ - (id)findClass:(Class)clz target:(id)target method:(NSString *)name promise:(Do
|
||||
[invocation invoke];
|
||||
} @catch (NSException *exception) {
|
||||
DoricLog(@"CallNative Error:%@", exception.reason);
|
||||
[self.doricContext.driver.registry onException:exception];
|
||||
[self.doricContext.driver.registry onException:exception source:self.doricContext.source];
|
||||
}
|
||||
};
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
|
Reference in New Issue
Block a user