Skip to content

refactor: throw the framework RuntimeException when an image extension is missing - #10824

Merged
paulbalandan merged 14 commits into
codeigniter4:4.8from
sgr1806-20:fix/image-exception-missing-extension
Nov 25, 2026
Merged

paulbalandan merged 14 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 a host without
the GD extension fatalised with "Call to undefined method" instead of
throwing a catchable exception.

Rather than re-adding an exception factory, GDHandler now throws
CodeIgniter\Exceptions\RuntimeException, naming the handler and the missing
extension — the same shape ImageMagickHandler's guard already used. For
consistency, ImageMagickHandler now uses the framework exception class as
well, instead of the native \RuntimeException.

The PHPStan baseline entry that suppressed the undefined-method call
(utils/phpstan-baseline/staticMethod.notFound.neon) is obsolete, so the
baseline was regenerated with composer phpstan:baseline.

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 Resolved
Comment thread system/Images/Handlers/GDHandler.php Resolved
@sgr1806-20
sgr1806-20 force-pushed the fix/image-exception-missing-extension branch from 3548b8d to e39dec7 Compare November 25, 2026 07:48
@sgr1806-20 sgr1806-20 changed the title fix: throw RuntimeException when the GD extension is missing in GDHandler fix: throw the framework RuntimeException when an image extension is missing Nov 25, 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!

@paulbalandan paulbalandan changed the title fix: throw the framework RuntimeException when an image extension is missing refactor: throw the framework RuntimeException when an image extension is missing Nov 25, 2026
@carson-codeigniter4 carson-codeigniter4 Bot added refactor Pull requests that refactor code and removed bug Verified issues on the current code behavior or pull requests that will fix them labels Nov 25, 2026
@paulbalandan
paulbalandan merged commit 8a606ad into codeigniter4:4.8 Nov 25, 2026
54 checks passed
@paulbalandan

Copy link
Copy Markdown
Member

Thank you, @sgr1806-20 , for your first contribution!

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. refactor Pull requests that refactor code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants