-
Notifications
You must be signed in to change notification settings - Fork 0
fix: allow adding an error note in media library and metabox #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -276,8 +276,11 @@ class ImageConverter extends Converter { | |||||||||||||||||||||||||||||||||
| const end = performance.now() | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // If the resulting image is bigger than the input, return the original file unchanged. | ||||||||||||||||||||||||||||||||||
| if ( convertedBlob.size > file.size ) { | ||||||||||||||||||||||||||||||||||
| throw new Error( `Resulting image is bigger than the input, skipping conversion.` ) | ||||||||||||||||||||||||||||||||||
| if ( convertedBlob.size < file.size ) { | ||||||||||||||||||||||||||||||||||
| const error = new Error( 'Resulting image is bigger than the input, skipping conversion.' ) | ||||||||||||||||||||||||||||||||||
| error.name = 'FileSizeExceededError' | ||||||||||||||||||||||||||||||||||
| error.isDisplayNote = true | ||||||||||||||||||||||||||||||||||
| throw error | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
278
to
284
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical bug: Size comparison logic is inverted. The condition 🐛 Proposed fix // If the resulting image is bigger than the input, return the original file unchanged.
- if ( convertedBlob.size < file.size ) {
+ if ( convertedBlob.size > file.size ) {
const error = new Error( 'Resulting image is bigger than the input, skipping conversion.' )
error.name = 'FileSizeExceededError'
error.isDisplayNote = true
throw error
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Get the file extension for the new format | ||||||||||||||||||||||||||||||||||
|
|
@@ -306,7 +309,8 @@ class ImageConverter extends Converter { | |||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| return { file: outFile, metadata: conversionMetadata } | ||||||||||||||||||||||||||||||||||
| } catch ( error ) { | ||||||||||||||||||||||||||||||||||
| throw new Error( `Failed to convert image: ${ error.message }` ) | ||||||||||||||||||||||||||||||||||
| error.message = `Failed to convert image: ${ error.message }` | ||||||||||||||||||||||||||||||||||
| throw error | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error handling path needs internationalization.
The error messages on lines 98-100 are hardcoded in English, unlike other strings in this file that use
esc_html__(). For consistency with WordPress i18n practices, these should be translatable.Also, line 98 has a minor syntax issue: missing space after
echo.🌐 Proposed fix for i18n and formatting
if ( $cimo['errorName'] === 'FileSizeExceededError' ) { - echo'<p>The WebP version of this image was larger than the original, so the original file was kept instead.</p>'; - echo '<p>You can try lowering the image quality setting to generate a smaller WebP file.</p>'; - echo '<p>Change the file type if needed.</p>'; + echo '<p>' . esc_html__( 'The WebP version of this image was larger than the original, so the original file was kept instead.', 'cimo-image-optimizer' ) . '</p>'; + echo '<p>' . esc_html__( 'You can try lowering the image quality setting to generate a smaller WebP file.', 'cimo-image-optimizer' ) . '</p>'; + echo '<p>' . esc_html__( 'Change the file type if needed.', 'cimo-image-optimizer' ) . '</p>'; }🤖 Prompt for AI Agents