Add comprehensive error handling to image lifecycle#61
Merged
Conversation
Improvements to create_image: - Catch and report Docker build failures with clear error messages - Re-raise exception to fail tests appropriately Improvements to delete_image: - Guard against nil @image (if build failed) - Wrap container cleanup in error handling to continue if issues occur - Catch individual container cleanup failures and continue - Handle NotFoundError if image already removed - Always attempt image removal even if container cleanup fails - Add informative status messages for debugging Benefits: - Tests fail gracefully with clear error messages - Cleanup attempts even after failures (prevents resource leaks) - Better visibility into what's happening during cleanup - Prevents cascading failures from cleanup issues Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds robust error handling to image build and cleanup operations to prevent resource leaks and provide better visibility into failures.
Changes
In
create_image:In
delete_image:@image(if build never completed)NotFoundErrorif image already removedProblem Solved
Before: If Docker image build failed, cleanup would crash trying to remove a nil image. If container cleanup failed, image removal would be skipped, leaving dangling images.
After: Cleanup is resilient and continues even when errors occur, preventing resource leaks.
Benefits
✅ Graceful failures - Clear error messages when builds fail
✅ Prevents resource leaks - Cleanup attempts even after failures
✅ Better debugging - Status messages show what's happening
✅ Resilient cleanup - Individual failures don't prevent overall cleanup
Testing
✅ All existing tests pass with new error handling
✅ Verified
delete_imagehandles nil@imagesafely✅ Cleanup messages appear in test output
✅ No behavioral changes for successful test runs