From: Jeff King <peff@peff.net>
To: Emily Shaffer <nasamuffin@google.com>
Cc: "brian m. carlson" <sandals@crustytoothpaste.net>,
Git List <git@vger.kernel.org>, Jonathan Nieder <jrn@google.com>,
Jose Lopes <jabolopes@google.com>,
Aleksandr Mikhailov <avmikhailov@google.com>
Subject: Re: Proposal/Discussion: Turning parts of Git into libraries
Date: Wed, 22 Feb 2023 14:34:31 -0500 [thread overview]
Message-ID: <Y/ZuR9zs3peUfO0g@coredump.intra.peff.net> (raw)
In-Reply-To: <CAJoAoZkMR9Acy7thVs-_e=Fz8wwjoDGDKb46wmwn8yxk0ODGow@mail.gmail.com>
On Fri, Feb 17, 2023 at 02:49:51PM -0800, Emily Shaffer wrote:
> > Personally, I'd like to see some sort of standard error type (whether
> > integral or not) that would let us do more bubbling up of errors and
> > less die(). I don't know if that's in the cards, but I thought I'd
> > suggest it in case other folks are interested.
>
> Yes!!! We have talked about this a lot internally - but this is one
> thing that will be difficult to introduce into Git without making
> parts of the codebase a little uglier. Since obviously C doesn't have
> an intrinsic to do this, we'll have to roll our own, which means that
> manipulating it consistently at function exits might end up pretty
> ugly. So hearing that there's interest outside of my team to come up
> with such a type makes me optimistic that we can figure out a
> neat-enough solution.
Here are some past discussions on what I thought would be a good
approach to error handling. The basic idea is to replace the "pass a
strbuf that people shove error messages into" approach with an error
context struct that has a callback. And that callback can then stuff
them into a strbuf, or report them directly, or even die.
This thread sketches out the idea, though sadly I no longer have the
more fleshed-out patches I mentioned there:
https://lore.kernel.org/git/20160927191955.mympqgylrxhkp24n@sigill.intra.peff.net/
And then the sub-thread starting here discusses a similar approach:
https://lore.kernel.org/git/20171103191309.sth4zjokgcupvk2e@sigill.intra.peff.net/
It does mean passing a "struct error_context" just about everywhere.
Though since the context doesn't change very much and most calls are
just forwarding it along, it would probably also be reasonable to have a
thread-local global context, and push/pop from it (sort of a poor man's
dynamic scoping).
One thing that strategy doesn't help with, though, that your
libification might want: it's not very machine-readable. The error
reporters would still fundamentally be working with strings. So a
libified process can know "OK, writing this ref failed, and I have some
error messages in a buffer". But the calling code can't know specifics
like "it failed because we tried to open file 'foo' and it got EPERM".
We _could_ design an error context that stores individual errno values
or codes in a list, but having each caller report those specific errors
is a much bigger job (and ongoing maintenance burden as we catalogue and
give an identifier to each error).
-Peff
next prev parent reply other threads:[~2023-02-22 19:34 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-17 21:12 Proposal/Discussion: Turning parts of Git into libraries Emily Shaffer
2023-02-17 21:21 ` brian m. carlson
2023-02-17 21:38 ` Emily Shaffer
2023-02-17 22:41 ` brian m. carlson
2023-02-17 22:49 ` Emily Shaffer
2023-02-22 19:34 ` Jeff King [this message]
2023-02-24 20:31 ` Emily Shaffer
2023-02-24 21:41 ` Jeff King
2023-02-24 22:59 ` Junio C Hamano
2023-02-17 22:04 ` rsbecker
2023-02-17 22:48 ` brian m. carlson
2023-02-17 22:57 ` Junio C Hamano
2023-02-18 1:59 ` demerphq
2023-02-18 10:36 ` Phillip Wood
2023-03-23 23:22 ` Felipe Contreras
2023-03-23 23:30 ` rsbecker
2023-03-23 23:34 ` Felipe Contreras
2023-03-23 23:42 ` rsbecker
2023-03-23 23:55 ` Felipe Contreras
2023-03-24 19:27 ` rsbecker
2023-03-24 21:21 ` Felipe Contreras
2023-03-24 22:06 ` rsbecker
2023-03-24 22:29 ` Felipe Contreras
2023-02-21 21:42 ` Emily Shaffer
2023-02-22 0:22 ` Junio C Hamano
2023-02-18 4:05 ` Elijah Newren
2023-02-21 22:06 ` Emily Shaffer
2023-02-22 8:23 ` Elijah Newren
2023-02-22 19:25 ` Jeff King
2023-02-21 19:09 ` Taylor Blau
2023-02-21 22:27 ` Emily Shaffer
2023-02-22 1:44 ` Victoria Dye
2023-02-25 1:48 ` Jonathan Tan
2023-02-22 14:55 ` Derrick Stolee
2023-02-24 21:06 ` Emily Shaffer
2023-03-23 23:37 ` Felipe Contreras
2023-03-23 23:44 ` rsbecker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y/ZuR9zs3peUfO0g@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=avmikhailov@google.com \
--cc=git@vger.kernel.org \
--cc=jabolopes@google.com \
--cc=jrn@google.com \
--cc=nasamuffin@google.com \
--cc=sandals@crustytoothpaste.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).