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

[PATCH] print an error message for invalid path

From
Dmitry Potapov <dpotapov@gmail.com>
Date
Oct 11, 2008, 16:39 UTC
Message-ID
<20081011163937.GA21650@dpotapov.dyndns.org>
In-Reply-To
<48EAFBC2.7020305@viscovery.net>

If verification of path failed, it is always better to print an error message saying this than relying on the caller function to print a meaningful error message (especially when the callee already prints error message for another situation).

Because the callers of add_index_entry_with_check() did not print any error message, it resulted that the user would not notice the problem when checkout if an invalid path failed.

Signed-off-by: Dmitry Potapov <dpotapov@gmail.com>
---
On Tue, Oct 07, 2008 at 08:03:46AM +0200, Johannes Sixt wrote:
Show 5 quoted lines
> 
> Look at the original patch. You did not change the behavior except to
> write more error messages. Maybe I misunderstand the words "to error out".
> I understand them as "to detect an error and return early", but not "write
> an error message".

For me, to "error out" means to show an error to the user. Usually, it implies that the program will return after that, though not necessary immediately. (Like gcc may print an error but it continues to parse the program and may report more errors).

You are right that I have not changed anything in terms of exiting earlier, and because I am aware about any commonly accepted definition of what "error out" means, I have replaced the comment with less ambiguous and detail description.

 builtin-update-index.c |    2 +-
 read-cache.c           |    6 ++++--
 2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/builtin-update-index.c b/builtin-update-index.c
index 417f972..3a2291b 100644
--- a/builtin-update-index.c
+++ b/builtin-update-index.c
@@ -218,7 +218,7 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,
 	struct cache_entry *ce;
 
 	if (!verify_path(path))
-		return -1;
+		return error("Invalid path '%s'", path);
 
 	len = strlen(path);
 	size = cache_entry_size(len);
diff --git a/read-cache.c b/read-cache.c
index 901064b..aff6390 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -591,8 +591,10 @@ struct cache_entry *make_cache_entry(unsigned int mode,
 	int size, len;
 	struct cache_entry *ce;
 
-	if (!verify_path(path))
+	if (!verify_path(path)) {
+		error("Invalid path '%s'", path);
 		return NULL;
+	}
 
 	len = strlen(path);
 	size = cache_entry_size(len);
@@ -874,7 +876,7 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e
 	if (!ok_to_add)
 		return -1;
 	if (!verify_path(ce->name))
-		return -1;
+		return error("Invalid path '%s'", ce->name);
 
 	if (!skip_df_check &&
 	    check_file_directory_conflict(istate, ce, pos, ok_to_replace)) {
-- 
1.6.0.2.447.g64b01
Previous: Johannes Sixt
Message 7 of 7 in “make prefix_path() never return NULL”
  1. make prefix_path() never return NULLDmitry Potapov, Oct 5, 2008
  2. do not segfault if make_cache_entry failedDmitry Potapov, Oct 5, 2008
  3. error out if path is invalidDmitry Potapov, Oct 5, 2008
  4. Johannes SixtOct 6, 2008
  5. Dmitry PotapovOct 7, 2008
  6. Johannes SixtOct 7, 2008
  7. print an error message for invalid pathDmitry Potapov, Oct 11, 2008

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.