Re: thoughts on error passing, was Re: [PATCH 2/2] fsck: handle bad trees like other errors
- From
Jeff King <peff@peff.net>
- Date
- Sep 28, 2016, 06:54 UTC
- Message-ID
- <20160928065451.klz4okmag3ksz3gu@sigill.intra.peff.net>
- In-Reply-To
- <1475017054.13103.3.camel@frank>
On Tue, Sep 27, 2016 at 06:57:34PM -0400, David Turner wrote:
Show 26 quoted lines
> > int report_error(struct error_context *err, const char *fmt, ...)
> > {
> > if (err->fn) {
> > va_list ap;
> > va_start(ap, fmt);
> > err->fn(err->data, fmt, ap);
> > va_end(ap);
> > }
> > return -1;
> > }
> >
> > Then low-level functions just take a context and do:
> >
> > return report_error(&err, "some error: %s", foo);
> >
> > And then the callers would pick one of a few generic error contexts:
> >
> > - passing NULL silences the errors
>
> Overall, +1.
>
> I guess I would rather have a sentinel value for silencing errors,
> because I'm worried that someone might read NULL as "don't handle the
> errors, just die". Of course, code review would hopefully catch this,
> but even so, it would be easier to read foo(x, y, silence_errors) than
> foo(x, y, null).Yeah, I waffled on that. If you look carefully, you'll note that the report_error() I showed above would actually require such a "{ NULL, NULL }" global.
I don't plan to make any patches immediately for this, but I'll let it percolate and consider whether it makes sense to try out for a future series.
-Peff