Skip to content

Handle image import setup failures#657

Open
yusufhay wants to merge 3 commits into
WordPress:developfrom
yusufhay:fix/image-import-error-handling
Open

Handle image import setup failures#657
yusufhay wants to merge 3 commits into
WordPress:developfrom
yusufhay:fix/image-import-error-handling

Conversation

@yusufhay

@yusufhay yusufhay commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

What?

Adds explicit error handling for image import setup failures.

Why?

The image import ability writes generated image data to a temporary file and then sideloads it into the media library. If WordPress cannot create the temporary file, or if the image MIME type cannot be mapped to a file extension, the ability should return a clear WP_Error instead of continuing with invalid file state.

How?

Checks the result of wp_tempnam() before writing image data. Also checks the file extension returned by wp_get_default_extension_for_mime_type() and deletes the temporary file before returning an error when the MIME type cannot be mapped.

Use of AI Tools

AI assistance: Yes
Tool(s): Codex / ChatGPT
Model(s): GPT-5
Used for: Reviewing the image import control flow for unhandled failure paths and drafting the minimal guards. I reviewed the change and PR description before submitting.

Testing Instructions

  1. Install and activate this PR build of the AI plugin.
  2. Enable image generation and connect a provider that supports image generation.
  3. Generate an image and import it into the media library.
  4. Confirm the image is imported successfully and its media fields are preserved as before.
  5. To validate the failure handling, simulate an unmapped image MIME type when calling the image import ability and confirm it returns a WP_Error instead of attempting to sideload a file with an invalid extension.

Screenshots or screencast

Not applicable. This PR does not change the UI.

Changelog Entry

Fixed - Return clear errors when generated image import setup fails.

Open WordPress Playground Preview

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: yusufhay <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@codecov

codecov Bot commented Jun 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.61%. Comparing base (64e8032) to head (d078baa).

Additional details and impacted files
@@              Coverage Diff              @@
##             develop     #657      +/-   ##
=============================================
+ Coverage      74.57%   74.61%   +0.04%     
- Complexity      1754     1758       +4     
=============================================
  Files             85       85              
  Lines           7548     7561      +13     
=============================================
+ Hits            5629     5642      +13     
  Misses          1919     1919              
Flag Coverage Δ
unit 74.61% <100.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dkotter dkotter left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

While I'm all for hardening existing code, I'm trying to understand in what situations these scenarios will happen. Reading the PR description doesn't give me a good idea of what scenarios these problems will occur or how to go about reproducing the problems myself.

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.

2 participants