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

Re: [PATCH v4 1/2] usage: Introduce error_errno corresponding to die_errno

From
Junio C Hamano <gitster@pobox.com>
Date
May 8, 2011, 18:10 UTC
Message-ID
<7v39kpt64y.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1304839851-6477-2-git-send-email-artagnon@gmail.com>
Ramkumar Ramachandra <artagnon@gmail.com> writes:
Show 10 quoted lines
> diff --git a/git-compat-util.h b/git-compat-util.h
> index 40498b3..7b82038 100644
> --- a/git-compat-util.h
> +++ b/git-compat-util.h
> @@ -241,6 +241,7 @@ extern NORETURN void usagef(const char *err, ...) __attribute__((format (printf,
>  extern NORETURN void die(const char *err, ...) __attribute__((format (printf, 1, 2)));
>  extern NORETURN void die_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));
>  extern int error(const char *err, ...) __attribute__((format (printf, 1, 2)));
> +extern int error_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));
>  extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));

Anybody remotely familiar with die_errno() would at least expect that the new and improved error_errno() function would give the errno neatly formatted via strerror() in the message, but that is not what the function does.

Show 17 quoted lines
> diff --git a/usage.c b/usage.c
> index b5e67e3..c89efcc 100644
> --- a/usage.c
> +++ b/usage.c
> @@ -107,6 +107,16 @@ int error(const char *err, ...)
>  	return -1;
>  }
>  
> +int error_errno(const char *err, ...)
> +{
> +	va_list params;
> +
> +	va_start(params, err);
> +	error_routine(err, params);
> +	va_end(params);
> +	return -errno;
> +}
Can error_routine() do something to cause errno to change?

For that matter, I suspect that the caller who would _care_ about what kind of error it got would need to save it away itself anyway. For example, it is not entirely clear if the callsite of this function in your other patch is correct. Can rollback_lock_file() cause errno to change?

	git_config(git_rerere_gc_config, NULL);
	dir = opendir(git_path("rr-cache"));
	if (!dir) {
+		int err = errno;
-		rollback_lock_file(&write_lock);
-		return error_errno("Unable to open rr-cache directory");
+		error("Untable to open rr-cache directory: %s", strerror(err));
+		return -err;
	}

I would prefer to do without introducing a confusingly named API function whose first and only usecase does not even suggest it would be useful.

Previous: Ramkumar RamachandraNext: Ramkumar Ramachandra
Message 11 of 13 in “rerere: Expose an API corresponding to 'clear' functionality”
  1. rerere: Expose an API corresponding to 'clear' functionalityRamkumar Ramachandra, Apr 11, 2011
  2. Junio C HamanoApr 11, 2011
  3. rerere: Expose an API corresponding to 'clear' functionalityRamkumar Ramachandra, Apr 13, 2011
  4. Jonathan NiederApr 13, 2011
  5. rerere: Expose an API corresponding to 'clear' functionalityRamkumar Ramachandra, May 6, 2011
  6. Junio C HamanoMay 6, 2011
  7. Ramkumar RamachandraMay 7, 2011
  8. 0/2 Libify rerere: clear and gcRamkumar Ramachandra, May 8, 2011
  9. 1/2 usage: Introduce error_errno corresponding to die_errnoRamkumar Ramachandra, May 8, 2011
  10. Ramkumar RamachandraMay 8, 2011
  11. Junio C HamanoMay 8, 2011
  12. 2/2 rerere: Libify "rerere clear" and "rerere gc"Ramkumar Ramachandra, May 8, 2011
  13. Junio C HamanoMay 8, 2011

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.