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

[BUG] incorrect error message in "git fsck" for empty loose objects

From
Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Date
Jan 23, 2012, 10:19 UTC
Message-ID
<vpqfwf6en6e.fsf@bauges.imag.fr>
Hi,

If a loose object is empty, "git fsck" reports it as corrupt (which is good), but with the following error message:

$ git fsck Checking object directories: 100% (256/256), done. fatal: failed to read object c1738f6288c9e5d5e58da00ced34d284ae93976c: Invalid argument $ cat .git/objects/c1/738f6288c9e5d5e58da00ced34d284ae93976c $ ls -l .git/objects/c1/738f6288c9e5d5e58da00ced34d284ae93976c -r--r--r-- 1 moy synchron 0 Jan 20 16:20 .git/objects/c1/738f6288c9e5d5e58da00ced34d284ae93976c

"Invalid argument" is really not the error message one would expect. Before that, git used to say:

   fatal: loose object c1738f6288c9e5d5e58da00ced34d284ae93976c (stored in
   .git/objects/c1/738f6288c9e5d5e58da00ced34d28
   4ae93976c) is corrupt
Which was far better.

This bisects back to 3ba7a065527a (A loose object is not corrupt if it cannot be read due to EMFILE), which essentially boils down to:

--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2090,16 +2090,21 @@ void *read_sha1_file_repl(const unsigned char *sha1,
                          const unsigned char **replacement)
[...]
+       errno = 0;
+       data = read_object(repl, type, size);
        if (data) {
                if (replacement)
                        *replacement = repl;
                return data;
        }
 
+       if (errno != ENOENT)
+               die_errno("failed to read object %s", sha1_to_hex(sha1));
+

Thanks,
-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Next: Matthieu Moy
Message 1 of 2 in “[BUG] incorrect error message in "git fsck" for empty loose objects”
  1. Matthieu MoyJan 23, 2012
  2. fsck: give accurate error message on empty loose object filesMatthieu Moy, Feb 6, 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.