🟢 [L6] load_file 失败后 watcher 已清空但旧状态残留 #32

Closed
opened 2026-06-03 13:54:29 +08:00 by dailz · 1 comment
Owner

文件: tui/app.rs:144-190
分类: 状态一致性

问题: load_file 先清空 watcher,如果打开失败,旧 loading_statefile_path 残留,watcher 已丢失。

建议修复: 先暂存新状态,成功后原子替换;失败时完整保留旧状态或转 Error 状态。

**文件**: `tui/app.rs:144-190` **分类**: 状态一致性 **问题**: `load_file` 先清空 watcher,如果打开失败,旧 `loading_state` 和 `file_path` 残留,watcher 已丢失。 **建议修复**: 先暂存新状态,成功后原子替换;失败时完整保留旧状态或转 Error 状态。
dailz added the area/tuiseverity/lowbug labels 2026-06-03 13:54:29 +08:00
Author
Owner

已修复 — commit 967c11f

根因load_file 在第154行先清空 file_watcher,如果后续 ProgressiveFileReader::open 失败,? 提前返回导致 watcher 丢失,而 loading_statefile_path 仍残留旧值。

修复方式:重构为 build-then-swap 模式:

  • Phase 1:所有可失败操作(open、with_channels)在局部变量中完成,不修改 self
  • Phase 2:全部成功后一次性替换 self 状态
  • 失败时 self 完全不变,旧文件的 watcher/loading_state/file_path 完整保留

测试test_file_watcher_preserved_on_nonexistent_file 验证失败后 watcher、file_path、loading_state 均保留。全量 129 tests 通过。

**已修复** — commit 967c11f **根因**:`load_file` 在第154行先清空 `file_watcher`,如果后续 `ProgressiveFileReader::open` 失败,`?` 提前返回导致 watcher 丢失,而 `loading_state` 和 `file_path` 仍残留旧值。 **修复方式**:重构为 build-then-swap 模式: - Phase 1:所有可失败操作(open、with_channels)在局部变量中完成,不修改 self - Phase 2:全部成功后一次性替换 self 状态 - 失败时 self 完全不变,旧文件的 watcher/loading_state/file_path 完整保留 **测试**:`test_file_watcher_preserved_on_nonexistent_file` 验证失败后 watcher、file_path、loading_state 均保留。全量 129 tests 通过。
dailz closed this issue 2026-06-11 17:23:50 +08:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dailz/logViewer#32