1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 01:47:34 +00:00

LibGfx/WebP: Redo error handling

Most places used to call `context.error()` to report an error,
which would set the context's state to `Error` and then return an
`Error::from_string_literal()`.

This is somewhat elegant, but it doesn't work: Some functions this
code calls returns ErrorOr<>s that aren't created by `context.error()`,
and for these we wouldn't enter the error state.

Instead, manually check error-ness at the leaf entry functions of the
class:

1. Add a set_error() helper for functions returning bool
2. In the two functions returning ErrorOr<>, awkwardly check the error
   manually.  If this becomes a very common pattern, maybe we can add
   a `TRY_WITH_HANDLER(expr, error_lambda)` which would invoke a
   lambda on error. We could use that here to set the error code.

No real behavior change (except we enter the error state more often
when something goes wrong).
This commit is contained in:
Nico Weber 2023-05-07 20:38:25 -04:00 committed by Andreas Kling
parent bdba70b38f
commit ddc2cc886b
2 changed files with 53 additions and 27 deletions

View file

@ -31,6 +31,8 @@ public:
virtual ErrorOr<Optional<ReadonlyBytes>> icc_data() override;
private:
bool set_error(ErrorOr<void>&&);
WebPImageDecoderPlugin(ReadonlyBytes, OwnPtr<WebPLoadingContext>);
OwnPtr<WebPLoadingContext> m_context;