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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2024-10-02 at 22:16:00, Eric Sunshine wrote:
> 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

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux