@@ -187,7 +187,7 @@ def __init__(self,
187187 # 其他配置
188188 self .filepath = filepath
189189
190- self .call_all_plugin ('after_init' )
190+ self .call_all_plugin ('after_init' , safe = True )
191191
192192 """
193193 下面是decide系列方法,为了支持重写和增加程序动态性。
@@ -494,7 +494,7 @@ def download_photo(self, photo_id):
494494
495495 # 下面的方法为调用插件提供支持
496496
497- def call_all_plugin (self , group : str , ** extra ):
497+ def call_all_plugin (self , group : str , safe = True , ** extra ):
498498 plugin_list : List [dict ] = self .plugins .get (group , [])
499499 if plugin_list is None or len (plugin_list ) == 0 :
500500 return
@@ -509,7 +509,13 @@ def call_all_plugin(self, group: str, **extra):
509509
510510 ExceptionTool .require_true (plugin_class is not None , f'[{ group } ] 未注册的plugin: { key } ' )
511511
512- self .invoke_plugin (plugin_class , kwargs , extra , pinfo )
512+ try :
513+ self .invoke_plugin (plugin_class , kwargs , extra , pinfo )
514+ except BaseException as e :
515+ if safe is True :
516+ traceback_print_exec ()
517+ else :
518+ raise e
513519
514520 def invoke_plugin (self , plugin_class , kwargs : Any , extra : dict , pinfo : dict ):
515521 # 检查插件的参数类型
@@ -542,7 +548,7 @@ def invoke_plugin(self, plugin_class, kwargs: Any, extra: dict, pinfo: dict):
542548
543549 except JmcomicException as e :
544550 # 模块内部异常,通过不是插件抛出的,而是插件调用了例如Client,Client请求失败抛出的
545- self .handle_plugin_exception (e , pinfo , kwargs , plugin )
551+ self .handle_plugin_jmcomic_exception (e , pinfo , kwargs , plugin )
546552
547553 except BaseException as e :
548554 # 为插件兜底,捕获其他所有异常
@@ -575,11 +581,11 @@ def handle_plugin_valid_exception(self, e, pinfo: dict, kwargs: dict, plugin):
575581 # noinspection PyMethodMayBeStatic,PyUnusedLocal
576582 def handle_plugin_unexpected_error (self , e , pinfo : dict , kwargs : dict , plugin ):
577583 msg = str (e )
578- jm_log ('plugin.error' , f'插件 [{ plugin .plugin_key } ],运行遇到未捕获异常,异常信息: { msg } ' )
584+ jm_log ('plugin.error' , f'插件 [{ plugin .plugin_key } ],运行遇到未捕获异常,异常信息: [ { msg } ] ' )
579585 raise e
580586
581587 # noinspection PyMethodMayBeStatic,PyUnusedLocal
582- def handle_plugin_exception (self , e , pinfo : dict , kwargs : dict , plugin ):
588+ def handle_plugin_jmcomic_exception (self , e , pinfo : dict , kwargs : dict , plugin ):
583589 msg = str (e )
584590 jm_log ('plugin.exception' , f'插件 [{ plugin .plugin_key } ] 调用失败,异常信息: [{ msg } ]' )
585591 raise e
0 commit comments