[cairo] error handling

Baz brian.ewins at gmail.com
Tue Jul 3 09:05:35 PDT 2007


On 01/07/07, Behdad Esfahbod <behdad at behdad.org> wrote:
> On Wed, 2007-05-30 at 11:07 +0100, Baz wrote:
> > So do you want this:
> >     if (status && status != CAIRO_STATUS_INVALID_GLYPH)
> >        _cairo_set_error(status);
> >     return status;
> >
> > or this:
> >     if (status == CAIRO_STATUS_INVALID_GLYPH)
> >        return status;
> >     if (status)
> >        _cairo_set_error(status);
> >     return CAIRO_STATUS_SUCCESS;
>
> Definitely not the second.  Why is it returning SUCCESS.

Well, I ended up writing the code the first way (see below), but
remember this is for functions which previously returned no status,
and which may leave cairo in an error state anyway (so you should have
been checking cairo's status). Now theres a new return value, which is
just there to communicate a warning. I can either have it return any
possible cairo status, and document that; or have it return only
warning statuses (ie invalid glyph) or success, and you continue to
find error statuses the old way.

> > I can see justifications for both. In the first case, you don't need
> > to check two different statuses to see if anything went wrong; in the
> > second case warnings and errors don't get mixed together. Which would
> > you prefer?
>
> I think you get the difference now.  In short, only
> CAIRO_STATUS_INVALID_GLYPH may be returned to user (or a better named
> one for cairo_show_text()), and all other errors handled like are
> currently done.

BTW I pushed the patches to work the first way a while back, to
http://gitweb.freedesktop.org/?p=users/brianewins/cairo;a=shortlog;h=return-status
a while back. gitweb seems to be a bit screwy right now and I can't
see diffs, but this patch:
http://gitweb.freedesktop.org/?p=users/brianewins/cairo;a=commit;h=11f367bfc7ffd5dcc97c3da4f23899b7ba4997be

... centralises the 'INVALID_GLYPH is special' logic.

Cheers,
Baz


More information about the cairo mailing list