Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions libs/autoDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,22 @@ def run(self):
if self.handle == 0:
self.listValue.emit(img_path)
if self.model == "paddle":
img = cv2.imdecode(
np.fromfile(img_path, dtype=np.uint8), cv2.IMREAD_COLOR
)
buf = np.fromfile(img_path, dtype=np.uint8)
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

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

np.fromfile(img_path, dtype=np.uint8) can raise (e.g., missing file, permission error, I/O error). Since run() catches Exception but then re-raises, these cases will still terminate the worker/app, which undermines the goal of “skip unreadable files”. Consider catching OSError/IOError around the fromfile/imdecode path, logging a warning, and continuing without re-raising.

Suggested change
buf = np.fromfile(img_path, dtype=np.uint8)
try:
buf = np.fromfile(img_path, dtype=np.uint8)
except (OSError, IOError) as e:
logger.warning(
"Failed to read image file %s due to an OS/I/O error: %s",
img_path,
e,
)
self.result_dic = None
continue

Copilot uses AI. Check for mistakes.
if buf.size == 0:
logger.warning(
"Failed to read the image's buffer. The file may be corrupted or in an unsupported format: %s",
img_path,
)
self.result_dic = None
continue
img = cv2.imdecode(buf, cv2.IMREAD_COLOR)
if img is None:
logger.warning(
"Failed to decode image file %s. The file may be corrupted or in an unsupported format.",
img_path,
)
self.result_dic = None
continue
Comment on lines +45 to +59
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

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

continue here skips the common post-processing block ("结果保存"), including findex += 1 and progressBarValue.emit(findex). This changes behavior for decode failures/empty buffers: skipped files no longer advance the progress bar, so the progress UI can finish below len_bar and the time-left estimate becomes inaccurate. Consider letting execution fall through to the existing self.result_dic is None handling (no continue), or increment/emit progress before continuing, so every input file advances progress consistently.

Copilot uses AI. Check for mistakes.
else:
h, w, _ = img.shape
if h > 32 and w > 32:
Expand Down
Loading