Skip to content

fix: Enhance error handling for wrong password scenarios in archive p…#402

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
dengzhongyuan365-dev:fix-4-30
Apr 28, 2026
Merged

fix: Enhance error handling for wrong password scenarios in archive p…#402
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
dengzhongyuan365-dev:fix-4-30

Conversation

@dengzhongyuan365-dev
Copy link
Copy Markdown
Contributor

…rocessing

  • Updated the handling of wrong password messages to treat them as fatal errors, aligning behavior with zip/7z.
  • Modified UI error message display to ensure consistent user feedback during password-related failures.
  • Implemented retry logic for loading archives after a wrong password error, improving user experience.

These changes improve the robustness of error handling and user interaction during archive operations.

bug: https://pms.uniontech.com/bug-view-355885.html

…rocessing

- Updated the handling of wrong password messages to treat them as fatal errors, aligning behavior with zip/7z.
- Modified UI error message display to ensure consistent user feedback during password-related failures.
- Implemented retry logic for loading archives after a wrong password error, improving user experience.

These changes improve the robustness of error handling and user interaction during archive operations.

bug: https://pms.uniontech.com/bug-view-355885.html
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @dengzhongyuan365-dev, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

这份代码 diff 主要涉及三个文件的修改,主要目的是改进错误处理流程(特别是密码错误处理)和修复窗口初始化时的布局问题。以下是对这些修改的详细审查意见:

1. 文件:3rdparty/clirarplugin/clirarplugin.cpp

修改内容:
统一了 RAR4 和 RAR5 密码错误的处理逻辑,不再区分版本,统一将密码错误视为致命错误(PFT_Error),并停止处理(return false)。

审查意见:

  • 逻辑与一致性(改进):

    • 优点:之前的代码对 RAR5 的密码错误返回 true,这通常意味着继续处理,可能导致循环尝试或状态不一致。修改后统一返回 false 并设置 PFT_Error,符合 ZIP/7z 的行为,使得不同压缩格式的错误处理策略在 UI 层面保持一致。这降低了 UI 层处理不同后端逻辑的复杂度。
    • 注意:这种修改意味着 UI 层(mainwindow.cpp)必须能够捕获到 ET_WrongPassword 并提供重试机制(从 diff 看,确实添加了相关逻辑)。如果 UI 没有重试机制,用户体验会变差(RAR5 以前可能有机会自动重试或提示,现在直接报错停止)。但结合 mainwindow.cpp 的修改,这是一个合理的架构调整。
  • 代码质量:

    • 代码更加简洁,去除了冗余的 if-else 分支。

2. 文件:src/main.cpp

修改内容:
Dtk::Widget::moveToCenter(&w) 的调用从 if (dbus.registerService(...)) 成功分支中移出,放在了 DBus 注册逻辑之后,确保无论 DBus 注册成功与否(例如第二次启动时服务已被占用),窗口都会居中。

审查意见:

  • 逻辑与 Bug 修复(改进):

    • 优点:这是一个重要的 Bug 修复。在之前的逻辑中,如果是第二次启动实例(DBus 服务已存在,registerService 失败),代码会跳过 moveToCenter。这导致在需要输入密码等弹窗场景下,主窗口可能停留在默认坐标(通常是左上角 (0,0)),导致后续弹窗位置异常。
    • 逻辑正确性:窗口的几何布局(居中)不应依赖于 DBus 服务的注册状态。将这两者解耦是正确的做法。
  • 代码质量:

    • 注释清晰地解释了修改原因("second launch path"),非常有助于后续维护。

3. 文件:src/source/mainwindow.cpp

修改内容:

  1. handleJobErrorFinished 中,调用 showErrorMessage 时增加了第三个参数 true
  2. slotFailureRetry 中增加了 case FI_Load: 分支,实现了加载(解压/预览)失败时的重试逻辑。

审查意见:

  • 逻辑与功能(改进):

    • 重试机制:配合 clirarplugin.cpp 的修改,当发生密码错误时,现在 UI 可以正确显示错误并提供重试选项。新增的 FI_Load 分支通过调用 loadArchive(archivePath) 重新加载归档文件,实现了"输入错误密码 -> 报错 -> 用户重试 -> 重新加载"的闭环。
    • 参数传递showErrorMessage(..., true) 中的 true 很可能是指示显示"重试"按钮的标志。这使得错误处理更加灵活。
  • 代码安全与健壮性:

    • 空指针/空字符串检查:在 FI_Load 分支中,使用了 if (!archivePath.isEmpty()) 进行检查。这是一个好的防御性编程习惯,防止 m_stUnCompressParameter.strFullPath 为空时导致未定义行为或无效操作。如果路径为空,则回退到主页(PI_Home),逻辑合理。
  • 代码性能:

    • loadArchive 涉及文件 I/O 和可能的解析操作,这是重试必须的代价,没有明显的性能问题。

总结与建议

这份 diff 整体质量很高,主要解决了以下问题:

  1. 统一了后端错误处理策略(RAR 密码错误)。
  2. 修复了窗口初始化的布局 Bug(DBus 注册失败时不居中)。
  3. 完善了前端的错误恢复流程(增加了加载失败的重试逻辑)。

建议:

  1. 测试覆盖:建议重点测试以下场景:
    • RAR5 文件密码错误:确认是否直接弹出错误提示,且提示框包含"重试"按钮。
    • 点击重试后:确认是否能重新弹出密码输入框,且输入正确密码后能正常解压。
    • 多开/第二次启动:确认在已有实例运行时,新触发的事件(如通过命令行或文件关联打开)弹出的窗口位置是否居中。
  2. 代码注释mainwindow.cppshowErrorMessage 的第三个参数 true 如果是魔法数字,建议在函数声明中使用枚举或具名常量(如 bool bShowRetryButton = true)以提高可读性,虽然目前的上下文已经比较清晰。

总体而言,这是一次逻辑严密、注释清晰的改进提交。

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: dengzhongyuan365-dev, lzwind

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@dengzhongyuan365-dev
Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot deepin-bot Bot merged commit 9885646 into linuxdeepin:master Apr 28, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants