Skip to content

Commit 0754d5e

Browse files
author
erickangxu
committed
fix: 增强错误处理,确保错误信息完整并添加日志标识
1 parent 346e944 commit 0754d5e

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

‎playwright/src/playwrightx/utils.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,15 @@ export function parseErrorCases(
221221

222222
// 检查 suites 是否为空
223223
if (!jsonData.suites || jsonData.suites.length === 0) {
224-
if (jsonData.errors.length > 0) {
224+
if (jsonData.errors && jsonData.errors.length > 0) {
225225
// 处理存在的错误
226226
for (const error of jsonData.errors) {
227-
const errorMessage = error.message;
228-
const errorStack = error.stack;
229-
const errorLocation = `${error.location.file}:${error.location.line}:${error.location.column}`;
230-
const errorSnippet = error.snippet;
227+
const errorMessage = error.message || "";
228+
const errorStack = error.stack || "";
229+
const errorLocation = error.location
230+
? `${error.location.file}:${error.location.line}:${error.location.column}`
231+
: "未知位置";
232+
const errorSnippet = error.snippet || "";
231233

232234
// 构建错误信息的结构
233235
const errorResult = {
@@ -521,7 +523,7 @@ export function parseJsonContent(
521523
data: { config?: { rootDir?: string }; suites?: Suite[]; errors?: Error[]; stats?: Stats },
522524
rootDir: string | null = null,
523525
): Record<string, SpecResult[]> {
524-
log.info("开始解析 JSON 内容...");
526+
log.info("-------开始解析 JSON 内容...-------");
525527
const rootPath = data.config?.rootDir || rootDir;
526528
log.info(`使用根路径: ${rootPath}`);
527529
const caseResults: Record<string, SpecResult[]> = {};

0 commit comments

Comments
 (0)