git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] Make error message after failing commit_lock_file() less confusing
@ 2015-11-30 11:40 SZEDER Gábor
  2015-12-01 23:17 ` Jeff King
  2015-12-02  4:28 ` Eric Sunshine
  0 siblings, 2 replies; 8+ messages in thread
From: SZEDER Gábor @ 2015-11-30 11:40 UTC (permalink / raw)
  To: Jeff King; +Cc: git, SZEDER Gábor

The error message after a failing commit_lock_file() call sometimes
looks like this, causing confusion:

  $ git remote add remote git@server.com/repo.git
  error: could not commit config file .git/config
  # Huh?!
  # I didn't want to commit anything, especially not my config file!

While in the narrow context of the lockfile module using the verb
'commit' in the error message makes perfect sense, in the broader
context of git the word 'commit' already has a very specific meaning,
hence the confusion.

Reword these error messages to say "could not write" instead of "could
not commit".

While at it, include strerror in the error messages after writing the
config file or the credential store fails to provide some information
about the cause of the failure, and update the style of the error
message after writing the reflog fails to match surrounding error
messages (i.e. no '' around the pathname and no () around the error
description).

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---

The error message is of course bikeshedable.
Some callers of commit_lock_file() say something like "could not move
updated whatever file <path> into place: <strerror>" on error.  While
it's truer to the meaning of the original error message and conveys
more exactly what went wrong (i.e. the actual writing had already
finished at that point, it's the move that failed), I think those
details are not necessary and the short and simple "could not write"
is better.

 config.c           | 6 ++++--
 credential-store.c | 3 ++-
 fast-import.c      | 2 +-
 refs.c             | 2 +-
 4 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/config.c b/config.c
index 248a21ab94..86a5eb2571 100644
--- a/config.c
+++ b/config.c
@@ -2144,7 +2144,8 @@ int git_config_set_multivar_in_file(const char *config_filename,
 	}
 
 	if (commit_lock_file(lock) < 0) {
-		error("could not commit config file %s", config_filename);
+		error("could not write config file %s: %s", config_filename,
+		      strerror(errno));
 		ret = CONFIG_NO_WRITE;
 		lock = NULL;
 		goto out_free;
@@ -2330,7 +2331,8 @@ int git_config_rename_section_in_file(const char *config_filename,
 	fclose(config_file);
 unlock_and_out:
 	if (commit_lock_file(lock) < 0)
-		ret = error("could not commit config file %s", config_filename);
+		ret = error("could not write config file %s: %s",
+			    config_filename, strerror(errno));
 out:
 	free(filename_buf);
 	return ret;
diff --git a/credential-store.c b/credential-store.c
index 00aea3aa30..fc67d16c10 100644
--- a/credential-store.c
+++ b/credential-store.c
@@ -64,7 +64,8 @@ static void rewrite_credential_file(const char *fn, struct credential *c,
 		print_line(extra);
 	parse_credential_file(fn, c, NULL, print_line);
 	if (commit_lock_file(&credential_lock) < 0)
-		die_errno("unable to commit credential store");
+		die_errno("unable to write credential store: %s",
+			  strerror(errno));
 }
 
 static void store_credential_file(const char *fn, struct credential *c)
diff --git a/fast-import.c b/fast-import.c
index e3b421d514..3c65edb5c4 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -1824,7 +1824,7 @@ static void dump_marks(void)
 
 	dump_marks_helper(f, 0, marks);
 	if (commit_lock_file(&mark_lock)) {
-		failure |= error("Unable to commit marks file %s: %s",
+		failure |= error("Unable to write file %s: %s",
 			export_marks_file, strerror(errno));
 		return;
 	}
diff --git a/refs.c b/refs.c
index 132eff52ca..b1c7b229b7 100644
--- a/refs.c
+++ b/refs.c
@@ -4684,7 +4684,7 @@ int reflog_expire(const char *refname, const unsigned char *sha1,
 					get_lock_file_path(lock->lk));
 			rollback_lock_file(&reflog_lock);
 		} else if (commit_lock_file(&reflog_lock)) {
-			status |= error("unable to commit reflog '%s' (%s)",
+			status |= error("unable to write reflog %s: %s",
 					log_file, strerror(errno));
 		} else if (update && commit_ref(lock)) {
 			status |= error("couldn't set %s", lock->ref_name);
-- 
2.6.3.420.g7bbb372

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] Make error message after failing commit_lock_file() less confusing
  2015-11-30 11:40 [PATCH] Make error message after failing commit_lock_file() less confusing SZEDER Gábor
@ 2015-12-01 23:17 ` Jeff King
  2015-12-02  2:19   ` Junio C Hamano
  2015-12-02  4:28 ` Eric Sunshine
  1 sibling, 1 reply; 8+ messages in thread
From: Jeff King @ 2015-12-01 23:17 UTC (permalink / raw)
  To: SZEDER Gábor; +Cc: git

On Mon, Nov 30, 2015 at 12:40:53PM +0100, SZEDER Gábor wrote:

> The error message after a failing commit_lock_file() call sometimes
> looks like this, causing confusion:
> 
>   $ git remote add remote git@server.com/repo.git
>   error: could not commit config file .git/config
>   # Huh?!
>   # I didn't want to commit anything, especially not my config file!

I like the intent of this patch; I've had the same "huh" moment myself.

> The error message is of course bikeshedable.

You chose "write", which I think is OK. It's really a "rename", and
maybe that matters for some values of errno. I'd guess in practice
probably not (the likely reason is going to be something like EPERM).
And I can't think of a concise way to express rename (just saying
"rename" is confusing, too, without indicating that it's from the
tempfile to the final resting place).

So perhaps "write" is the best we can do.

-Peff

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Make error message after failing commit_lock_file() less confusing
  2015-12-01 23:17 ` Jeff King
@ 2015-12-02  2:19   ` Junio C Hamano
  0 siblings, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2015-12-02  2:19 UTC (permalink / raw)
  To: Jeff King; +Cc: SZEDER Gábor, git

Jeff King <peff@peff.net> writes:

> On Mon, Nov 30, 2015 at 12:40:53PM +0100, SZEDER Gábor wrote:
>
>> The error message after a failing commit_lock_file() call sometimes
>> looks like this, causing confusion:
>> 
>>   $ git remote add remote git@server.com/repo.git
>>   error: could not commit config file .git/config
>>   # Huh?!
>>   # I didn't want to commit anything, especially not my config file!
>
> I like the intent of this patch; I've had the same "huh" moment myself.
>
>> The error message is of course bikeshedable.
>
> You chose "write", which I think is OK. It's really a "rename", and
> maybe that matters for some values of errno. I'd guess in practice
> probably not (the likely reason is going to be something like EPERM).
> And I can't think of a concise way to express rename (just saying
> "rename" is confusing, too, without indicating that it's from the
> tempfile to the final resting place).
>
> So perhaps "write" is the best we can do.

Yeah, "finalize" came to me but "write" is far easier to understand
by laypeople.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Make error message after failing commit_lock_file() less confusing
  2015-11-30 11:40 [PATCH] Make error message after failing commit_lock_file() less confusing SZEDER Gábor
  2015-12-01 23:17 ` Jeff King
@ 2015-12-02  4:28 ` Eric Sunshine
  2015-12-03 10:30   ` SZEDER Gábor
  1 sibling, 1 reply; 8+ messages in thread
From: Eric Sunshine @ 2015-12-02  4:28 UTC (permalink / raw)
  To: SZEDER Gábor; +Cc: Jeff King, Git List

On Mon, Nov 30, 2015 at 6:40 AM, SZEDER Gábor <szeder@ira.uka.de> wrote:
> The error message after a failing commit_lock_file() call sometimes
> looks like this, causing confusion:
>
>   $ git remote add remote git@server.com/repo.git
>   error: could not commit config file .git/config
>   # Huh?!
>   # I didn't want to commit anything, especially not my config file!
>
> While in the narrow context of the lockfile module using the verb
> 'commit' in the error message makes perfect sense, in the broader
> context of git the word 'commit' already has a very specific meaning,
> hence the confusion.
>
> Reword these error messages to say "could not write" instead of "could
> not commit".
>
> While at it, include strerror in the error messages after writing the
> config file or the credential store fails to provide some information
> about the cause of the failure, and update the style of the error
> message after writing the reflog fails to match surrounding error
> messages (i.e. no '' around the pathname and no () around the error
> description).
>
> Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
> ---
> diff --git a/config.c b/config.c
> @@ -64,7 +64,8 @@ static void rewrite_credential_file(const char *fn, struct credential *c,
>                 print_line(extra);
>         parse_credential_file(fn, c, NULL, print_line);
>         if (commit_lock_file(&credential_lock) < 0)
> -               die_errno("unable to commit credential store");
> +               die_errno("unable to write credential store: %s",
> +                         strerror(errno));

Hmm, this is already calling die_errno(), so adding another strerror()
to the mix seems superfluous.

>  }
>
>  static void store_credential_file(const char *fn, struct credential *c)
> diff --git a/fast-import.c b/fast-import.c
> @@ -1824,7 +1824,7 @@ static void dump_marks(void)
>
>         dump_marks_helper(f, 0, marks);
>         if (commit_lock_file(&mark_lock)) {
> -               failure |= error("Unable to commit marks file %s: %s",
> +               failure |= error("Unable to write file %s: %s",
>                         export_marks_file, strerror(errno));

Since you're already doing some normalization of the error messages
with this patch, do you want to drop capitalization on this one?

>                 return;
>         }

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Make error message after failing commit_lock_file() less confusing
  2015-12-02  4:28 ` Eric Sunshine
@ 2015-12-03 10:30   ` SZEDER Gábor
  2015-12-03 10:31     ` [PATCH v2] " SZEDER Gábor
  0 siblings, 1 reply; 8+ messages in thread
From: SZEDER Gábor @ 2015-12-03 10:30 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: Jeff King, Git List


Quoting Eric Sunshine <sunshine@sunshineco.com>:

>> diff --git a/config.c b/config.c
>> @@ -64,7 +64,8 @@ static void rewrite_credential_file(const char  
>> *fn, struct credential *c,
>>                 print_line(extra);
>>         parse_credential_file(fn, c, NULL, print_line);
>>         if (commit_lock_file(&credential_lock) < 0)
>> -               die_errno("unable to commit credential store");
>> +               die_errno("unable to write credential store: %s",
>> +                         strerror(errno));
>
> Hmm, this is already calling die_errno(), so adding another strerror()
> to the mix seems superfluous.

Oops, of course.

>>  }
>>
>>  static void store_credential_file(const char *fn, struct credential *c)
>> diff --git a/fast-import.c b/fast-import.c
>> @@ -1824,7 +1824,7 @@ static void dump_marks(void)
>>
>>         dump_marks_helper(f, 0, marks);
>>         if (commit_lock_file(&mark_lock)) {
>> -               failure |= error("Unable to commit marks file %s: %s",
>> +               failure |= error("Unable to write file %s: %s",
>>                         export_marks_file, strerror(errno));
>
> Since you're already doing some normalization of the error messages
> with this patch, do you want to drop capitalization on this one?

The neighboring error messages are capitalized as well, as are many  
(but not all) other error and warning messages in fast-import.c.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2] Make error message after failing commit_lock_file() less confusing
  2015-12-03 10:30   ` SZEDER Gábor
@ 2015-12-03 10:31     ` SZEDER Gábor
  2015-12-16 11:22       ` [PATCH] credential-store: don't pass strerror to die_errno() SZEDER Gábor
  0 siblings, 1 reply; 8+ messages in thread
From: SZEDER Gábor @ 2015-12-03 10:31 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Jeff King, Eric Sunshine, git, SZEDER Gábor

The error message after a failing commit_lock_file() call sometimes
looks like this, causing confusion:

  $ git remote add remote git@server.com/repo.git
  error: could not commit config file .git/config
  # Huh?!
  # I didn't want to commit anything, especially not my config file!

While in the narrow context of the lockfile module using the verb
'commit' in the error message makes perfect sense, in the broader
context of git the word 'commit' already has a very specific meaning,
hence the confusion.

Reword these error messages to say "could not write" instead of "could
not commit".

While at it, include strerror in the error messages after writing the
config file fails, to provide some information about the cause of the
failure, and update the style of the error message after writing the
reflog fails, to match surrounding error messages (i.e. no '' around
the pathname and no () around the error description).

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---

Notes:
    Changes since v1:
    * Don't pass strerror() to die_errno().

 config.c           | 6 ++++--
 credential-store.c | 2 +-
 fast-import.c      | 2 +-
 refs.c             | 2 +-
 4 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/config.c b/config.c
index 248a21ab94..86a5eb2571 100644
--- a/config.c
+++ b/config.c
@@ -2144,7 +2144,8 @@ int git_config_set_multivar_in_file(const char *config_filename,
 	}
 
 	if (commit_lock_file(lock) < 0) {
-		error("could not commit config file %s", config_filename);
+		error("could not write config file %s: %s", config_filename,
+		      strerror(errno));
 		ret = CONFIG_NO_WRITE;
 		lock = NULL;
 		goto out_free;
@@ -2330,7 +2331,8 @@ int git_config_rename_section_in_file(const char *config_filename,
 	fclose(config_file);
 unlock_and_out:
 	if (commit_lock_file(lock) < 0)
-		ret = error("could not commit config file %s", config_filename);
+		ret = error("could not write config file %s: %s",
+			    config_filename, strerror(errno));
 out:
 	free(filename_buf);
 	return ret;
diff --git a/credential-store.c b/credential-store.c
index 00aea3aa30..54c4e04737 100644
--- a/credential-store.c
+++ b/credential-store.c
@@ -64,7 +64,7 @@ static void rewrite_credential_file(const char *fn, struct credential *c,
 		print_line(extra);
 	parse_credential_file(fn, c, NULL, print_line);
 	if (commit_lock_file(&credential_lock) < 0)
-		die_errno("unable to commit credential store");
+		die_errno("unable to write credential store");
 }
 
 static void store_credential_file(const char *fn, struct credential *c)
diff --git a/fast-import.c b/fast-import.c
index e3b421d514..3c65edb5c4 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -1824,7 +1824,7 @@ static void dump_marks(void)
 
 	dump_marks_helper(f, 0, marks);
 	if (commit_lock_file(&mark_lock)) {
-		failure |= error("Unable to commit marks file %s: %s",
+		failure |= error("Unable to write file %s: %s",
 			export_marks_file, strerror(errno));
 		return;
 	}
diff --git a/refs.c b/refs.c
index 132eff52ca..b1c7b229b7 100644
--- a/refs.c
+++ b/refs.c
@@ -4684,7 +4684,7 @@ int reflog_expire(const char *refname, const unsigned char *sha1,
 					get_lock_file_path(lock->lk));
 			rollback_lock_file(&reflog_lock);
 		} else if (commit_lock_file(&reflog_lock)) {
-			status |= error("unable to commit reflog '%s' (%s)",
+			status |= error("unable to write reflog %s: %s",
 					log_file, strerror(errno));
 		} else if (update && commit_ref(lock)) {
 			status |= error("couldn't set %s", lock->ref_name);
-- 
2.6.3.420.g7bbb372

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH] credential-store: don't pass strerror to die_errno()
  2015-12-03 10:31     ` [PATCH v2] " SZEDER Gábor
@ 2015-12-16 11:22       ` SZEDER Gábor
  2015-12-16 18:20         ` Jeff King
  0 siblings, 1 reply; 8+ messages in thread
From: SZEDER Gábor @ 2015-12-16 11:22 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Jeff King, git, SZEDER Gábor

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---

v2 fixed this, but it fell on the floor, I suppose because of the
maintainer switch.  Anyway, I should have noticed it while the patch
was still cooking, sorry.

 credential-store.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/credential-store.c b/credential-store.c
index fc67d16c1088..54c4e0473737 100644
--- a/credential-store.c
+++ b/credential-store.c
@@ -64,8 +64,7 @@ static void rewrite_credential_file(const char *fn, struct credential *c,
 		print_line(extra);
 	parse_credential_file(fn, c, NULL, print_line);
 	if (commit_lock_file(&credential_lock) < 0)
-		die_errno("unable to write credential store: %s",
-			  strerror(errno));
+		die_errno("unable to write credential store");
 }
 
 static void store_credential_file(const char *fn, struct credential *c)
-- 
2.7.0.rc0.37.g77d69b9

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] credential-store: don't pass strerror to die_errno()
  2015-12-16 11:22       ` [PATCH] credential-store: don't pass strerror to die_errno() SZEDER Gábor
@ 2015-12-16 18:20         ` Jeff King
  0 siblings, 0 replies; 8+ messages in thread
From: Jeff King @ 2015-12-16 18:20 UTC (permalink / raw)
  To: SZEDER Gábor; +Cc: Junio C Hamano, git

On Wed, Dec 16, 2015 at 12:22:55PM +0100, SZEDER Gábor wrote:

> Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
> ---
> 
> v2 fixed this, but it fell on the floor, I suppose because of the
> maintainer switch.  Anyway, I should have noticed it while the patch
> was still cooking, sorry.

Oops. I do remember seeing Eric point out the problem and I think I was
planning to fix it up before merging. But I didn't make a note in
whats-cooking, so Junio had no idea of my plan.

>  credential-store.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)

Patch is obviously correct. Thanks.

-Peff

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-12-16 18:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-30 11:40 [PATCH] Make error message after failing commit_lock_file() less confusing SZEDER Gábor
2015-12-01 23:17 ` Jeff King
2015-12-02  2:19   ` Junio C Hamano
2015-12-02  4:28 ` Eric Sunshine
2015-12-03 10:30   ` SZEDER Gábor
2015-12-03 10:31     ` [PATCH v2] " SZEDER Gábor
2015-12-16 11:22       ` [PATCH] credential-store: don't pass strerror to die_errno() SZEDER Gábor
2015-12-16 18:20         ` Jeff King

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).