git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC PATCH 1/1] Add a type for errors

From
PWPhillip 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.
> 
> 
Previous: Oswald BuddenhagenNext: Emily Shaffer
Message 7 of 21 in “Typed errors”
  1. 0/1 Typed errorsbrian m. carlson, Sep 30, 2024
  2. 1/1 Add a type for errorsbrian m. carlson, Sep 30, 2024
  3. Junio C HamanoSep 30, 2024
  4. brian m. carlsonSep 30, 2024
  5. Patrick SteinhardtOct 21, 2024
  6. Oswald BuddenhagenOct 1, 2024
  7. Phillip WoodOct 2, 2024
  8. Emily ShafferOct 1, 2024
  9. brian m. carlsonOct 2, 2024
  10. Phillip WoodOct 2, 2024
  11. brian m. carlsonOct 2, 2024
  12. Eric SunshineOct 2, 2024
  13. brian m. carlsonOct 2, 2024
  14. Eric SunshineOct 3, 2024
  15. Junio C HamanoOct 3, 2024
  16. Eric SunshineOct 3, 2024
  17. brian m. carlsonOct 4, 2024
  18. phillip.wood123@gmail.comOct 4, 2024
  19. Richard KerryOct 4, 2024
  20. Emily ShafferOct 3, 2024
  21. phillip.wood123@gmail.comOct 4, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.