Re: [RFC PATCH 1/1] Add a type for errors
- From
- Phillip Wood <phillip.wood123@gmail.com>
- Date
- Oct 2, 2024, 14:01 UTC
- Message-ID
- <dc1a70b3-9a0f-4c5e-931d-8b3b91335ec7@gmail.com>
- In-Reply-To
- <ZvwVZs-HLy0RiP3E@ugly>
Hi Oswald
On 01/10/2024 16:29, Oswald Buddenhagen wrote:
Show 17 quoted lines
> On Mon, Sep 30, 2024 at 10:03:52PM +0000, brian m. carlson wrote:
>> + case GIT_ERR_MULTIPLE:
>> + strbuf_addf(buf, _("multiple errors:\n"));
>> + for (size_t i = 0; i < me->count; i++) {
>> + git_error_strbuf(buf, me->errs[i]);
>> + strbuf_addstr(buf, "\n");
>> + }
>> + }
>
> ah. i was wondering how you'd address this ("this" being non-fatal
> errors piling up), as i'm facing the same problem in a project of mine.
>
> the problem is that one can either impose a very rigid formatting (as
> you do here), or provide formatting options, which can get arbitrarily
> complex. so i wonder whether one shouldn't pursue a hybrid approach
> instead: singular return values for low-level functions that either work
> or fail fatally, and error callbacks for higher-level functionality?That's a good point - the rigid formatting is easy to implement but is not ideal from the user's point of view. Ideally we'd compose a coherent message with the data from the various errors but as you say that's not trivial. I wonder if there are any good examples out there that we could use as inspiration. The ones I'm aware of (rust's anyhow and svn's svn_error_compose) go for a rigid approach. Glib's GError punts the problem entirely by forbidding multiple errors.
Best Wishes
Phillip
> btw, the switch misses breaks. > >