Re: [RFC PATCH 1/1] Add a type for errors
- From
brian m. carlson <sandals@crustytoothpaste.net>
- Date
- Oct 2, 2024, 22:24 UTC
- Message-ID
- <Zv3IHd0c4_0NPjOK@tapette.crustytoothpaste.net>
- In-Reply-To
- <CAPig+cRkA58wr_Pn-uhVM0zFA7B0hnArXDeumrjnWrgBbG64Yw@mail.gmail.com>
On 2024-10-02 at 22:16:00, Eric Sunshine wrote:
Show 9 quoted lines
> I'm not sure I understand your response to Phillip's observation.
> Idiomatic error handling in Go:
>
> if oid, err := repo_get_oid(r, "HEAD"); err != nil {
> return err;
> }
>
> seems much closer to Phillip's more succinct example than to the more
> verbose example using GIT_ERROR_SUCCESS().I don't think that approach works if you want to use `oid`, since it scopes just to the `if` statement (and any relevant `else`). If `oid` were already defined, then you would need to omit the colon in `:=`, or the compiler would complain about "no new variables".
That's why I usually see this:
oid, err := repo_get_oid(r, "HEAD")
if err != nil {
return err
}which is much more like what Phillip's more verbose example shows.
-- brian m. carlson (they/them or he/him) Toronto, Ontario, CA