Re: Libification project (SoC)
- From
- Luiz Fernando N. Capitulino <lcapitulino@mandriva.com.br>
- Date
- Mar 17, 2007, 19:58 UTC
- Message-ID
- <20070317195832.2af87c06@home.brethil>
- In-Reply-To
- <20070316231646.GB4508@spearce.org>
On Fri, 16 Mar 2007 19:16:46 -0400 "Shawn O. Pearce" <spearce@spearce.org> wrote:
| "Luiz Fernando N. Capitulino" <lcapitulino@mandriva.com.br> wrote: | > I think the right solution is to get rid of die() from functions that | > are supposed to be an interface, set errno if needed and return -1 | > or NULL. | | And then make their callers (if they are above the public API layer) | die instead. In some cases this might imply an undesirable change | in the error message produced, as necessary details that are included | today would be unavailable in the caller.
Exactly!
One simple example of an important error message that would be lost can be found in read-cache.c:read_cache_from():
o index file smaller than expected
I've found a possible solution, though.
Take a look at Rusty's solution for the same problem in module-init-tools:
"""
/* We use error numbers in a loose translation... */
static const char *insert_moderror(int err)
{
switch (err) {
case ENOEXEC:
return "Invalid module format";
case ENOENT:
return "Unknown symbol in module, or unknown parameter (see dmesg)";
case ENOSYS:
return "Kernel does not have module support";
default:
return strerror(err);
}
}
"""Instead of calling strerror() directly for error generated when inserting a module, the insmod() function calls insert_moderror() which provides the desirable mapping.
I think we could have something like that for each git's module, eg, git_cache_strerror(), git_commit_strerror() and so on.
Does this look reasonable?
-- Luiz Fernando N. Capitulino