Skip to content

fix: throw RuntimeException when the GD extension is missing in GDHandler - #10824

Open
sgr1806-20 wants to merge 13 commits into
codeigniter4:4.8from
sgr1806-20:fix/image-exception-missing-extension
Open

sgr1806-20 wants to merge 13 commits into
codeigniter4:4.8from
sgr1806-20:fix/image-exception-missing-extension

Conversation

@sgr1806-20

@sgr1806-20 sgr1806-20 commented Nov 24, 2026 •

Copy link
Copy Markdown

Description

GDHandler called a factory that no longer exists:

throw ImageException::forMissingExtension('GD');

On 4.8 that method is undefined (ImageException doesn't define it, and
FrameworkException::forMissingExtension() was removed), so on a host
without the GD extension this fatalised with "Call to undefined method"
instead of throwing a catchable exception.

Rather than re-adding an exception factory, this follows the approach used
by ImageMagickHandler and throws a RuntimeException naming the handler and
the missing extension.

Verified by instantiating GDHandler on a PHP build without GD: before,
Error: Call to undefined method; after, RuntimeException: The
"...\GDHandler" handler requires the "gd" PHP extension.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@carson-codeigniter4 carson-codeigniter4 Bot added needs template Opened issues not following the bug form template 4.8 PRs that target the `4.8` branch. labels Nov 24, 2026
@carson-codeigniter4

carson-codeigniter4 Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Resolved

Hi there, @sgr1806-20! 👋

It looks like this pull request does not follow our template:

Please update the description to follow the template. The needs template label will be removed automatically once it does.


Hi there, @sgr1806-20! 👋

Thank you for sending this PR!

We expect the following in all Pull Requests (PRs).

Important

We expect all code changes or bug-fixes to be accompanied by one or more tests added to our test suite to prove the code works.

If pull requests do not comply with the above, they will likely be closed. Since we are a team of volunteers, we don't have any more time to work
on the framework than you do. Please make it as painless for your contributions to be included as possible.

See https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/pull_request.md

@sgr1806-20 sgr1806-20 changed the title Fix/image exception missing extension fix: add ImageException::forMissingExtension() for the GD handler Nov 24, 2026
@carson-codeigniter4 carson-codeigniter4 Bot added bug Verified issues on the current code behavior or pull requests that will fix them and removed needs template Opened issues not following the bug form template labels Nov 24, 2026

@michalsn michalsn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, but I would rather follow the path we have in the ImageMagickHandler: https://github.com/codeigniter4/CodeIgniter4/blob/4.8/system/Images/Handlers/ImageMagickHandler.php#L45

@carson-codeigniter4 carson-codeigniter4 Bot added testing Pull requests that changes tests only and removed testing Pull requests that changes tests only labels Nov 24, 2026
@sgr1806-20 sgr1806-20 changed the title fix: add ImageException::forMissingExtension() for the GD handler fix: throw RuntimeException when the GD extension is missing in GDHandler Nov 24, 2026
@sgr1806-20

Copy link
Copy Markdown
Author

Thanks, but I would rather follow the path we have in the ImageMagickHandler: https://github.com/codeigniter4/CodeIgniter4/blob/4.8/system/Images/Handlers/ImageMagickHandler.php#L45

Thanks! Switched GDHandler to the same RuntimeException idiom as
ImageMagickHandler. Reverted the ImageException method and the language
string, and dropped the test for the guard since that path isn't reachable
in CI (GD is always loaded), same as ImageMagickHandler's guard.

@sgr1806-20

Copy link
Copy Markdown
Author

CI is green on this revision apart from the Psalm (8.3) job, which is
pre-existing on 4.8 — it fails the same way on e3bf470 (CURL_HTTP_VERSION_3
with PHP 8.3, in system/HTTP/CURLRequest.php and its test), which this PR
doesn't touch.

PHP Static Analysis passes now that the stale baseline entry
(utils/phpstan-baseline/staticMethod.notFound.neon) is removed.

@paulbalandan

Copy link
Copy Markdown
Member

Please rebase.

@sgr1806-20
sgr1806-20 force-pushed the fix/image-exception-missing-extension branch from e5303ee to 0aeec13 Compare November 24, 2026 12:25
@sgr1806-20

sgr1806-20 commented Nov 24, 2026 •

Copy link
Copy Markdown
Author

Please rebase.

Rebased onto the latest 4.8 (d4da78c). Diff unchanged.

Comment thread utils/phpstan-baseline/loader.neon Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please don't hand-edit this file. run composer phpstan:baseline instead.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

regenerated with composer phpstan:baseline - header is now 37 and the staticMethod.notFound.neon file is no longer produced.

Comment thread system/Images/Handlers/GDHandler.php Outdated
use Config\Images;
use GdImage;
use Override;
use RuntimeException;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is the framework's RuntimeException, not the native one.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

switched to CodeIgniter\Exceptions\RuntimeException. note that ImageMagickHandler still imports the native RuntimeException — left that alone as it's outside this PR's scope, but happy to change it if you want.

…seline

- GDHandler now throws CodeIgniter\Exceptions\RuntimeException
- utils/phpstan-baseline regenerated with composer phpstan:baseline

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.8 PRs that target the `4.8` branch. bug Verified issues on the current code behavior or pull requests that will fix them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants