Skip to content

fix(core): don't terminate on exceptions escaping background tasks - #177

Draft
doogie99 wants to merge 1 commit into
ScanTailor-Advanced:masterfrom
doogie99:fix/background-task-exception-containment
Draft

fix(core): don't terminate on exceptions escaping background tasks#177
doogie99 wants to merge 1 commit into
ScanTailor-Advanced:masterfrom
doogie99:fix/background-task-exception-containment

Conversation

@doogie99

@doogie99 doogie99 commented Aug 4, 2026

Copy link
Copy Markdown

Problem

Worker threads only catch std::bad_alloc. Any other exception thrown during page processing — and the output/dewarping pipeline alone has dozens of throw sites (RasterDewarper, LinearSolver, OutputGenerator's margin checks, etc.) — unwinds to QThread's start wrapper and aborts the entire application via std::terminate(). The user loses their session with no indication of what went wrong.

We hit this in practice on macOS/arm64: before #30 was fixed, fillMarginsInPlace: the content area exceeds image rect. crashed the app when switching from the dewarping view to output. Any remaining or future throw site can still take the whole app down the same way.

Fix

  • LoadFileTask::operator(): catch std::exception around the processing chain and return an ErrorResult that displays the exception message in the image area, so the user sees what failed on which page instead of losing the app. std::bad_alloc is rethrown so the existing out-of-memory handling still works.
  • WorkerThreadPool / BackgroundExecutor: catch-all safety nets that log a warning instead of terminating.

Testing

Built and ran on macOS 26 (arm64, Qt 6.11). Before the #30 fix existed, this change converted the hard crash above into a visible per-page error message — which is also how the root cause was identified.

🤖 Generated with Claude Code

Worker threads only caught std::bad_alloc; any other exception thrown
during page processing unwound to QThread's start wrapper and aborted
the whole application via std::terminate(). Catch std::exception in
LoadFileTask and surface it as an in-app error page, and add catch-all
safety nets in WorkerThreadPool and BackgroundExecutor.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant