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

Re: Bug: bad errno report from lock_ref_sha1_basic() when contents bad

From
Thomas Rast <trast@student.ethz.ch>
Date
Apr 2, 2012, 18:12 UTC
Message-ID
<87bonam2a2.fsf@thomas.inf.ethz.ch>
In-Reply-To
<7vhax2ghy1.fsf@alter.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
Show 12 quoted lines
> Thomas Rast <trast@inf.ethz.ch> writes:
>
>> But in general, the "errno may
>> be crucial or worthless" interface of lock_ref_sha1_basic() seems a bit
>> broken...
>
> Sorry, but I am not sure what you mean by this.  The function is fairly
> careful using errno to base its decision and even saves errno when it
> calls helpers that may overwrite it, so the "interface" does not want "may
> be crucial or worthless".  The implementation may have been broken over
> time by many patches, but that is a different issue.  Which codepaths
> clobber errno, and is it something you can easily fix with a patch or two?

I meant something else, sorry for being so unclear and confused. In particular my comment was supposed to be about resolve_ref_unsafe().

It has two different failure modes:
* Some FS syscall went wrong, and errno is crucial for the user to debug
  it (e.g., ENOENT).
* Reading went fine, but we failed to parse the resulting buffer.  errno
  has some unknown value.

The user of the function needs to be aware of this distinction, and handle it accordingly. Otherwise it risks emitting outright wrong error messages, e.g., in my case I got

  thomas@thomas:~/g(next u+107)$ echo garbage >.git/refs/remotes/origin/master
  thomas@thomas:~/g(next u+107)$ g fetch
  error: unable to resolve reference refs/remotes/origin/master: No such file or directory
  From git://git.kernel.org/pub/scm/git/git
   ! [new branch]      master     -> origin/master  (unable to update local ref)

(The IRC user who asked about this was lucky because "Success" immediately told us that it was an error path not related to syscalls.)

-- 
Thomas Rast
trast@{inf,student}.ethz.ch
Previous: Junio C Hamano
Message 3 of 3 in “Bug: bad errno report from lock_ref_sha1_basic() when contents bad”
  1. Thomas RastApr 2, 2012
  2. Junio C HamanoApr 2, 2012
  3. Thomas RastApr 2, 2012

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.