✅ Fixed bulk conversion getting stuck on missing files ✅ Added robust error handling and timeout protection ✅ Improved JavaScript response parsing ✅ Added file existence validation ✅ Fixed missing PHP class imports ✅ Added comprehensive try-catch error recovery 🔧 Key fixes: - File existence checks before conversion attempts - 30-second timeout protection per file - Graceful handling of 500 errors and JSON parsing issues - Automatic continuation to next file on failures - Cache busting for JavaScript updates 🎯 Result: Bulk conversion now completes successfully even with missing files 🚀 Generated with Claude Code (https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
5.1 KiB
WebP Express Bulk Conversion Fix
This document describes the fixes applied to resolve the issue where bulk conversion gets stuck on missing files.
Problem Description
The WebP Express plugin was getting stuck during bulk conversion with errors like:
- "Converting uploads/2022/11/PASTA-LOVE-GROUPAGE.png failed"
- "Converting uploads/2022/09/MESOSES-crema.jpg. None of the converters in the stack could convert the image. failed"
The issue occurred because:
- Files referenced in the conversion queue no longer existed on the filesystem
- The plugin attempted to validate and convert non-existent files
- PHP exceptions were thrown that halted the entire bulk conversion process
- JavaScript error handling was inadequate, causing JSON parsing errors on 500 responses
Fixes Applied
1. File Existence Validation (lib/classes/Convert.php)
Location: Lines 61-67
// First check if file exists before doing any other validations
if (!file_exists($source)) {
return [
'success' => false,
'msg' => 'Source file does not exist: ' . $source,
'log' => '',
];
}
Purpose: Prevents the SanityCheck::absPathExistsAndIsFile() from throwing exceptions on missing files.
2. ConvertHelperIndependent Protection (lib/classes/ConvertHelperIndependent.php)
Location: Lines 613-620
// First check if file exists before doing any other validations
if (!file_exists($source)) {
return [
'success' => false,
'msg' => 'Source file does not exist: ' . $source,
'log' => '',
];
}
Purpose: Adds the same protection at the lower level conversion function.
3. Bulk Conversion List Filtering (lib/classes/BulkConvert.php)
Location: Lines 176-180
// Additional safety check: verify the file actually exists before adding to list
$fullPath = $dir . "/" . $filename;
if (!file_exists($fullPath)) {
continue; // Skip this file if it doesn't exist
}
Purpose: Prevents missing files from being added to the conversion queue in the first place.
4. Missing Import Fixes
Files Updated:
lib/classes/Convert.php- Added missing imports for BiggerThanSourceDummyFiles, DestinationOptions, EwwwTools, PathHelper, Pathslib/classes/ConvertHelperIndependent.php- Added PathHelper importlib/classes/BulkConvert.php- Added Config, ConvertHelperIndependent, ImageRoots, PathHelper, Paths imports
Purpose: Resolves PHP fatal errors caused by missing class imports.
5. JavaScript Version Update (lib/options/enqueue_scripts.php:12)
$ver = '4-cloudhost'; // Force browser cache refresh
6. JavaScript Error Handling (lib/options/js/bulk-convert.js)
A. Robust JSON Response Parsing (Lines 272-299)
// Handle different types of responses safely
if (typeof response.requestError === 'boolean' && response.requestError) {
result = { success: false, msg: 'Request failed', log: '' };
} else if (typeof response === 'string') {
try {
result = JSON.parse(response);
} catch (e) {
result = { success: false, msg: 'Invalid response received from server', log: '' };
}
} else if (typeof response === 'object') {
result = response;
} else {
result = { success: false, msg: 'Unexpected response type', log: '' };
}
B. AJAX Timeout and Error Handling (Lines 389-432)
timeout: 30000, // 30 second timeout per file
error: (jqXHR, textStatus, errorThrown) => {
// Detailed error reporting and automatic continuation to next file
}
C. Try-Catch Protection (Lines 262-422)
function responseCallback(response){
try {
// All response processing code protected
} catch (error) {
// Graceful error handling and continuation
}
}
D. Improved Error Processing (Lines 328-333)
// Only stop for critical errors (security nonce issues), not file-specific errors
if (result['stop'] && result['msg'] && result['msg'].indexOf('security nonce') !== -1) {
// Stop only for security errors
} else {
// Continue processing for file-specific errors
}
Result
With these fixes, the WebP Express plugin will now:
✅ Skip missing files during bulk conversion listing ✅ Handle missing files gracefully during conversion attempts ✅ Continue processing other files when one fails ✅ Timeout after 30 seconds per file to prevent hanging ✅ Only stop the process for critical security errors ✅ Provide clear error messages for failed conversions ✅ Handle 500 errors without breaking the JavaScript execution
Testing
The bulk conversion should no longer get stuck on missing files. Instead, it will:
- Log that specific files don't exist
- Continue with the next files in the queue
- Complete the conversion process for all existing files
- Show a summary of successful and failed conversions
Compatibility
These changes are backward compatible and do not affect:
- Normal image conversion functionality
- WebP serving via .htaccess rules
- Plugin settings and configuration
- Other plugin features
The fixes only improve the robustness of the bulk conversion feature.