Skip to content

Conversation

@GhostvOne
Copy link
Contributor

Show errors on image manipulation. related topic : spatie/laravel-medialibrary#3778

Show errors on image manipulation. related topic : spatie/laravel-medialibrary#3778
@freekmurze
Copy link
Member

This could be viewed as a breaking change.

Could you add a method to enable/disable this?

@GhostvOne
Copy link
Contributor Author

GhostvOne commented May 30, 2025

I can definitely add a method to enable or disable this behavior.

That said, I’m wondering if this is really a breaking change. Currently, when there's an issue with the image, the @imagecreatefromstring call simply fails silently and stop everything else, which could lead to harder-to-debug problems down the line. Removing the error suppression would actually make issues more visible, which might be desirable in most cases.

Wouldn't it be more consistent (and developer-friendly) to throw an exception or return an explicit error instead of failing silently? I'm happy to implement the toggle, but I wanted to raise the point in case improving error visibility is actually the preferred default behavior.

@freekmurze
Copy link
Member

I'm a bit afraid of people now getting error warnings where previously they would get none. But you're probably right that maybe we want to make this kind of situation more visible.

Change it to throwing an exception indeed, then users can easily determine themselves how it should be handled.

Throw exception instead of suppressing errors in imagecreatefromstring
try {
$image = imagecreatefromstring($contents);
} catch (Throwable $e) {
throw CouldNotLoadImage::make($path);
Copy link
Member

Choose a reason for hiding this comment

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

The reason why it failed is probably in the original exception, best to pass that on to CouldNotLoadImage

@GhostvOne
Copy link
Contributor Author

Most of other MR has the same failed task. It Seems to not be related to my MR

@GhostvOne GhostvOne requested a review from freekmurze May 31, 2025 18:37
$image = @imagecreatefromstring($contents);
try {
$image = imagecreatefromstring($contents);
} catch (Throwable $e) {
Copy link
Member

Choose a reason for hiding this comment

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

Do not use abbreviations: use $exception instead of $e

try {
$image = imagecreatefromstring($contents);
} catch (Throwable $e) {
throw CouldNotLoadImage::make($e);
Copy link
Member

Choose a reason for hiding this comment

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

Could you also add the path to the exception?

@GhostvOne GhostvOne requested a review from freekmurze June 3, 2025 13:45
@freekmurze freekmurze merged commit df315a4 into spatie:main Jun 4, 2025
1 of 4 checks passed
@freekmurze
Copy link
Member

Thanks!

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.

3 participants