bug fix: 修复由于语法错误导致预处理脚本或后处理脚本执行报错,而报错的行号是错误的问题
This commit is contained in:
parent
ab9443fed4
commit
3518a9a19a
|
@ -29,20 +29,26 @@ def exec_script(source, project_id, log, script_type, glb=None, loc=None):
|
||||||
loc = {}
|
loc = {}
|
||||||
loc['vars'] = vars
|
loc['vars'] = vars
|
||||||
loc['log'] = log
|
loc['log'] = log
|
||||||
|
loc['__name__'] = '__main__'
|
||||||
try:
|
try:
|
||||||
exec(source, glb, loc)
|
exec(source, glb, loc)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
tb = sys.exc_info()[-1]
|
if isinstance(e, SyntaxError):
|
||||||
script_tb = tb.tb_next
|
lineno = e.lineno
|
||||||
|
else:
|
||||||
|
tb = sys.exc_info()[-1]
|
||||||
|
while tb.tb_next:
|
||||||
|
tb = tb.tb_next
|
||||||
|
lineno = tb.tb_lineno
|
||||||
if script_type == 'PREPROCESSOR_SCRIPT':
|
if script_type == 'PREPROCESSOR_SCRIPT':
|
||||||
failure_message = '预处理脚本执行异常: m行号: %s, 错误信息: %s, 错误类型: %s' % (script_tb.tb_lineno, e.args[0], type(e))
|
failure_message = '预处理脚本执行异常: m行号: %s, 错误信息: %s, 错误类型: %s' % (lineno, e.args[0], type(e))
|
||||||
script_exception = PreScriptExecException(script_tb.tb_lineno, e.args[0], failure_message)
|
script_exception = PreScriptExecException(lineno, e.args[0], failure_message)
|
||||||
log.error('预处理脚本执行异常: 行号: %s, 错误信息: %s' % (script_exception.line_no, script_exception.value))
|
log.error('预处理脚本执行异常: 行号: %s, 错误信息: %s' % (script_exception.line_no, script_exception.value))
|
||||||
raise script_exception
|
raise script_exception
|
||||||
elif script_type == 'POSTPROCESSOR_SCRIPT':
|
elif script_type == 'POSTPROCESSOR_SCRIPT':
|
||||||
loc['failure'] = True # 后处理脚本异常时,将断言结果置为失败
|
loc['failure'] = True # 后处理脚本异常时,将断言结果置为失败
|
||||||
failure_message = '后处理脚本执行异常: 行号: %s, 错误信息: %s, 错误类型: %s' % (script_tb.tb_lineno, e.args[0], type(e))
|
failure_message = '后处理脚本执行异常: 行号: %s, 错误信息: %s, 错误类型: %s' % (lineno, e.args[0], type(e))
|
||||||
script_exception = PostScriptExecException(script_tb.tb_lineno, e.args[0], failure_message)
|
script_exception = PostScriptExecException(lineno, e.args[0], failure_message)
|
||||||
loc['failure_message'] = failure_message
|
loc['failure_message'] = failure_message
|
||||||
log.error(failure_message)
|
log.error(failure_message)
|
||||||
raise script_exception
|
raise script_exception
|
||||||
|
|
Loading…
Reference in New Issue