fix(cli): 翻译失败只输出单行错误

worker 与 batch 异常不再打印 traceback.format_exc,避免与主进程汇总重复输出。
This commit is contained in:
TermiNexus committed 2026-10-18 19:09:51 +08:00
1 parent 8cdef178a5
commit 92e467ae4c
1 file changed
+5 -7
+5 -7
View File
@@ -768,11 +768,9 @@ def _parallel_translate_worker(src_path: str, out_path: str, src_root: str, temp
trans._translate_file(src_path, out_path, prebuilt_ModuleSha1Map=prebuilt_ModuleSha1Map, dwarf_enabled=dwarf_enabled)
return ('ok', src_path, '')
except Exception as e:
# fail-fast(2026-08-18):include 文件编译出错立即终止整个编译进程
# (主进程收到 BrokenProcessPool 后取消剩余任务退出)。
# fail-fast:只输出单行错误(含源码定位),不打印 Python 内部调用栈
sys.stderr.write(
f"[FATAL] include 翻译失败,立即终止编译: {src_path}\n"
f"{traceback.format_exc()}\n")
f"[FATAL] 翻译失败: {src_path}\n{type(e).__name__}: {e}\n")
sys.stderr.flush()
os._exit(88)
@@ -852,13 +850,13 @@ def _parallel_translate_batch(batch: list, src_root: str, temp_dir: str, output_
# 不再收集错误继续翻译批内剩余文件(避免浪费大量时间)。主进程
# 收到 BrokenProcessPool/future 异常后取消全部剩余批次退出。
sys.stderr.write(
f"[FATAL] 文件翻译失败,立即终止编译: {src_path}\n"
f"{traceback.format_exc()}\n")
f"[FATAL] 文件翻译失败: {src_path}\n"
f"{type(e).__name__}: {e}\n")
sys.stderr.flush()
os._exit(88)
return (batch_errors, batch, per_file_times)
except Exception as e:
return ([(item[1], f'{e}\n{traceback.format_exc()}') for item in batch], batch, [])
return ([(item[1], f'{type(e).__name__}: {e}') for item in batch], batch, [])
# ==================================================================