Skip to content

Fix return in finally block silently suppressing exceptions#1763

Open
Otman404 wants to merge 2 commits intounclecode:mainfrom
Otman404:fix/return-in-finally-block
Open

Fix return in finally block silently suppressing exceptions#1763
Otman404 wants to merge 2 commits intounclecode:mainfrom
Otman404:fix/return-in-finally-block

Conversation

@Otman404
Copy link

@Otman404 Otman404 commented Feb 17, 2026

Summary

Move return results out of the finally block in MemoryAdaptiveDispatcher.run_urls since it was silently suppressing any exception propagating from the try or except blocks

List of files changed and why

  1. crawl4ai/async_dispatcher.py - Moved return results from inside the finally block to after it in MemoryAdaptiveDispatcher.run_urls

before

        finally:
            # Clean up
            memory_monitor.cancel()
            if self.monitor:
                self.monitor.stop()
            return results

after

        finally:
            # Clean up
            memory_monitor.cancel()
            if self.monitor:
                self.monitor.stop()
        return results
  1. same file - Re-raise exceptions after logging in the except block

before

  except Exception as e:
      if self.monitor:
          self.monitor.update_memory_status(f"QUEUE_ERROR: {str(e)}")

after

  except Exception as e:
      if self.monitor:
          self.monitor.update_memory_status(f"QUEUE_ERROR: {str(e)}")
      raise

How Has This Been Tested?

9/10 existing tests pass. The one failure (test_monitor_integration)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added/updated unit tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

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