Skip to content
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

Don't throw exception for broken images, but return "empty" image info. #52

Merged

Conversation

bobdenotter
Copy link
Member

Partial fix for bolt/bolt#6677

Just like when a file is 0 bytes, it should return an 'empty' image info, instead of throwing an exception.
The exception will just "break" the interface, and it won't tell the (end)user much.

Discussed this with Carson last night, and catching and filtering them out in the Bolt UI isn't optimal either, because it needs to be done in three places at least (the "files listing" page, the ajaxy listing in "pick from server" modals, and in the stack).

I'm for returning an "empty" image info, and present the user with a friendly warning in the user interface, that will also tell them which image is broken.

@bobdenotter bobdenotter changed the title Partial fix for Don't throw exception for broken images, but return "empty" image info. May 17, 2017
@bobdenotter
Copy link
Member Author

bobdenotter commented May 17, 2017

If we agree on the general approach of this change, I'll fix the tests! :-)

@GwendolenLynch
Copy link
Contributor

Well, I guess the same question has to be asked of the second exception in createSvgFromString() too … problem to battle, is the exceptions are really useful to know something went wrong.

… but not so useful for a stable UI. 😞

@CarsonF
Copy link
Member

CarsonF commented May 18, 2017

Generally I agree, but I think I'm going to switch sides for this case. We are just trying to display the info to the user, not really do anything with it (like make image modifications). An exception makes it hard for Twig since it doesn't handle it.

That said, we still need a way to determine if the image info is valid or not.
I think we should add an isValid(): bool method to Info. Both PHP and Twig can check for this and do whatever they need to do.

All the "empty" cases should be "invalid" too. Maybe rename (copy & deprecate) createEmpty method to createInvalid.

@CarsonF
Copy link
Member

CarsonF commented May 18, 2017

We should make sure thumbs handles the invalid object correctly instead of relying on an exception to be thrown.

@GwendolenLynch
Copy link
Contributor

We should make sure thumbs handles the invalid object correctly instead of relying on an exception to be thrown.

bolt/thumbs#45

@CarsonF CarsonF force-pushed the fix/dont-throw-exceptions-for-broken-jpgs-and-pngs branch from 5892254 to 061e906 Compare June 3, 2017 17:41
@CarsonF
Copy link
Member

CarsonF commented Jun 3, 2017

I added an createInvalid constructor method and deprecated createEmpty, since I don't think there's a case where we want to consider empty as valid.

@CarsonF CarsonF force-pushed the fix/dont-throw-exceptions-for-broken-jpgs-and-pngs branch from 061e906 to 740c90d Compare June 3, 2017 19:25
@GwendolenLynch
Copy link
Contributor

GwendolenLynch commented Jun 4, 2017

OK, the $valid on the constructor signature is really irking me, though setting it to true at that point is fine.

Thing is, the only time we care about changing that parameter is when we try to createFrom*(), and that need only happen in createInvalid() e.g.

public static function createInvalid()
{
    $invalid = new static(new Dimensions(0, 0), Type::unknown(), 0, 0, null, new Exif([]));
    $invalid->valid = false;

    return $invalid;
}

Note: Not marking approve/request as I'm happy to be convinced otherwise

@CarsonF
Copy link
Member

CarsonF commented Jun 4, 2017

Yeah that's fine. Feel free to change and merge.

…ject

instead of throwing exception when image parsing fails.

For this use case we hardly ever care why image parsing failed we just
want to show info about the image or default values. This is also mostly
done from Twig where exceptions cannot be caught. The valid property
allows us to handle the failure without breaking the view layer.
@GwendolenLynch GwendolenLynch force-pushed the fix/dont-throw-exceptions-for-broken-jpgs-and-pngs branch from 740c90d to 7a6c482 Compare June 4, 2017 06:05
@GwendolenLynch
Copy link
Contributor

Changed, making sure I didn't miss something (valid) on test, then I have just enough time to get this over the line 👍

@GwendolenLynch GwendolenLynch merged commit cb46869 into master Jun 4, 2017
@GwendolenLynch GwendolenLynch deleted the fix/dont-throw-exceptions-for-broken-jpgs-and-pngs branch June 4, 2017 06:08
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