Skip to content

Fix Load Images error handling - chain no longer runs forever on iteration errors#3141

Merged
joeyballentine merged 7 commits intomainfrom
copilot/fix-load-images-error-handling
Oct 19, 2025
Merged

Fix Load Images error handling - chain no longer runs forever on iteration errors#3141
joeyballentine merged 7 commits intomainfrom
copilot/fix-load-images-error-handling

Conversation

Copy link
Contributor

Copilot AI commented Oct 19, 2025

  • Understand the issue: When Load Images encounters errors during iteration (e.g., image dimension mismatches), the chain runs forever instead of showing an error
  • Identify root cause: In process.py, the iteration loop at line 799 calls next(generator_supplier) which can yield an Exception, but doesn't check if the returned value is an Exception before using it
  • Fix the issue: Add exception checking after line 799 to handle yielded exceptions properly based on fail_fast setting
  • Fix deferred_errors accumulation: Move deferred_errors initialization outside the while loop so errors accumulate across all iterations when fail_fast=False
  • Fix tests to import actual implementation: Updated tests to import the real Generator class from api.iter instead of using a copy
  • Fix formatting issues: Applied ruff formatter to ensure code style consistency
  • Fix pyright type checking: Added proper assertions to handle optional types in module loading
  • Run linters and tests to ensure no regressions - All tests pass and code is properly formatted

Summary

Fixed two issues with Load Images error handling and improved test quality:

  1. Exception Detection: Added check to detect when Generator yields an Exception and raise it properly
  2. Error Accumulation: Moved deferred_errors initialization outside the iteration loop so errors accumulate across all iterations when fail_fast=False
  3. Test Quality: Tests now import the actual Generator class from api.iter using importlib to avoid dependency issues
  4. Code Formatting: Applied ruff formatter to ensure consistent code style
  5. Type Safety: Added assertions for pyright type checking on module loading

Changes Made:

  1. backend/src/process.py:
    • Added exception checking (4 lines)
    • Fixed deferred_errors initialization position (1 line moved)
  2. backend/tests/test_generator_exception_handling.py:
    • Now imports actual Generator class instead of using a copy
    • 5 comprehensive unit tests including test for multiple exception handling
    • Fixed formatting to comply with project style guide
    • Added type assertions for pyright compatibility

How the Fix Works:

  • When Load Images encounters an error, the Generator yields an Exception object
  • The exception check detects this and raises it
  • The existing exception handler respects the "Stop on first error" setting:
    • If enabled: Stops immediately and shows the error
    • If disabled: Collects ALL errors across iterations and reports them at the end

Validation:

  • ✅ All 14 tests pass (9 existing + 5 new)
  • ✅ Tests now use actual Generator implementation, not a copy
  • ✅ Code passes ruff linter checks
  • ✅ Code passes ruff formatter checks
  • ✅ Code passes pyright type checking (0 errors)
  • ✅ No breaking changes to existing functionality
Original prompt

This section details on the original issue you should resolve

<issue_title>(nightly) Load Images - chain execution runs forever instead of showing an error</issue_title>
<issue_description>Information:

  • Chainner version: v0.24.2-nightly.2024-10.29
  • OS: Windows 11

Description
Errors triggered by images from Load Images don't stop the execution, the chain keeps running without doing anything. This does not happen when Load Images cannot find matching files, or two Load Images find a different number of files. It does happen for example when trying to Combine RGBA of images with different resolutions, Crop where dimensions reach outside the image, or using RGB where Gray image is expected.

Logs
main.log

</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #3057


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix infinite execution issue in Load Images Fix Load Images error handling - chain no longer runs forever on iteration errors Oct 19, 2025
Copilot AI requested a review from joeyballentine October 19, 2025 06:40
Copilot AI and others added 3 commits October 19, 2025 11:08
…ns during iteration

Co-authored-by: joeyballentine <34788790+joeyballentine@users.noreply.github.com>
Co-authored-by: joeyballentine <34788790+joeyballentine@users.noreply.github.com>
@joeyballentine joeyballentine force-pushed the copilot/fix-load-images-error-handling branch from ad5cedc to d6c2ff7 Compare October 19, 2025 16:08
@joeyballentine
Copy link
Member

@copilot The only issue with this is that it doesn't throw the errors at the end if fail_fast is false

…t=False

Co-authored-by: joeyballentine <34788790+joeyballentine@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 19, 2025

@copilot The only issue with this is that it doesn't throw the errors at the end if fail_fast is false

Fixed in commit 5d47dbc. Moved deferred_errors initialization outside the while loop so errors accumulate across all iterations when fail_fast=False. Added a test to verify multiple exceptions are properly collected and thrown at the end.

@joeyballentine
Copy link
Member

@copilot the tests you added aren't really tests if they don't import the actual thing being tested...

Co-authored-by: joeyballentine <34788790+joeyballentine@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 19, 2025

@copilot the tests you added aren't really tests if they don't import the actual thing being tested...

Fixed in commit b80a213. Tests now import the actual Generator class from api.iter using importlib (to avoid triggering sanic dependencies in api.__init__), instead of using a copy of the class. All 14 tests still pass.

@joeyballentine joeyballentine marked this pull request as ready for review October 19, 2025 16:35
@joeyballentine
Copy link
Member

@copilot you need to fix the formatting issues

Co-authored-by: joeyballentine <34788790+joeyballentine@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 19, 2025

@copilot you need to fix the formatting issues

Fixed in commit 82898ed. Applied ruff formatter to the test file - it added a blank line after the module docstring to comply with the project's style guide.

@joeyballentine
Copy link
Member

@copilot pyright has some issues with some things you did in the test

Co-authored-by: joeyballentine <34788790+joeyballentine@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 19, 2025

@copilot pyright has some issues with some things you did in the test

Fixed in commit 9c1ede6. Added assertions to handle the optional types from spec_from_file_location and spec.loader, which pyright was flagging. The code now passes pyright with 0 errors.

Copy link
Member

@joeyballentine joeyballentine left a comment

Choose a reason for hiding this comment

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

I feel like this is something I fixed in one of my follow-up PRs that got cancelled and I just forgot to redo it. Anyway, I tested this and its good, plus I appreciate the added tests for it.

@joeyballentine joeyballentine merged commit ce30560 into main Oct 19, 2025
28 checks passed
@joeyballentine joeyballentine deleted the copilot/fix-load-images-error-handling branch October 19, 2025 19:21
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.

(nightly) Load Images - chain execution runs forever instead of showing an error

2 participants