Re: Doesn't disambiguate between 'external command failed' and 'command not found'

3 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: Doesn't disambiguate between 'external command failed' and 'command not found'

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:51:33

Jeff King [off-list ref] writes:
On Wed, Jul 06, 2011 at 01:58:03PM -0400, Jeff King wrote:
quoted
quoted
Like this? I've replaced "Check the #!-line of the git-%s script." with
"Maybe git-%s is broken?" to be less technical and specific..
Yeah, looks good to me (unless somebody wants to do something more
elaborate to catch other exec problems, but I personally don't think
it's worth the effort).
One minor nit, though. I haven't been paying attention to the progress
of the gettext topics, but should this message:
quoted
+static const char bad_interpreter_advice[] =
+	"'%s' appears to be a git command, but we were not\n"
+	"able to execute it. Maybe git-%s is broken?";
Actually be inside _() for gettext?
I would mark it with N_() and then the calling site inside die() with _()
if I were doing this.

Re: Doesn't disambiguate between 'external command failed' and 'command not found'

From: Michael Schubert <hidden>
Date: 2016-06-15 22:51:33

On 07/07/2011 01:25 AM, Junio C Hamano wrote:
Jeff King [off-list ref] writes:
quoted
One minor nit, though. I haven't been paying attention to the progress
of the gettext topics, but should this message:
quoted
+static const char bad_interpreter_advice[] =
+	"'%s' appears to be a git command, but we were not\n"
+	"able to execute it. Maybe git-%s is broken?";
Actually be inside _() for gettext?
I would mark it with N_() and then the calling site inside die() with _()
if I were doing this.
Sorry for the delay.

-- >8 --

Subject: [PATCH] help_unknown_cmd: do not propose an "unknown" cmd

When executing an external shell script like `git foo` with the following
shebang "#!/usr/bin/not/existing", execvp returns 127 (ENOENT). Since
help_unknown_cmd proposes the use of all external commands similar to
the name of the "unknown" command, it suggests the just failed command
again. Stop it and give some advice to the user.

Helped-by: Jeff King [off-list ref]
Signed-off-by: Michael Schubert <redacted>
---
 help.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/help.c b/help.c
index 7654f1b..4219355 100644
--- a/help.c
+++ b/help.c
@@ -302,6 +302,10 @@ static void add_cmd_list(struct cmdnames *cmds, struct cmdnames *old)
 #define SIMILARITY_FLOOR 7
 #define SIMILAR_ENOUGH(x) ((x) < SIMILARITY_FLOOR)
 
+static const char bad_interpreter_advice[] =
+	N_("'%s' appears to be a git command, but we were not\n"
+	"able to execute it. Maybe git-%s is broken?");
+
 const char *help_unknown_cmd(const char *cmd)
 {
 	int i, n, best_similarity = 0;
@@ -326,6 +330,14 @@ const char *help_unknown_cmd(const char *cmd)
 		int cmp = 0; /* avoid compiler stupidity */
 		const char *candidate = main_cmds.names[i]->name;
 
+		/*
+		 * An exact match means we have the command, but
+		 * for some reason exec'ing it gave us ENOENT; probably
+		 * it's a bad interpreter in the #! line.
+		 */
+		if (!strcmp(candidate, cmd))
+			die(_(bad_interpreter_advice), cmd, cmd);
+
 		/* Does the candidate appear in common_cmds list? */
 		while (n < ARRAY_SIZE(common_cmds) &&
 		       (cmp = strcmp(common_cmds[n].name, candidate)) < 0)
-- 
1.7.6.132.g91c244.dirty

Re: Doesn't disambiguate between 'external command failed' and 'command not found'

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:51:34

Michael Schubert [off-list ref] writes:
Sorry for the delay.
Thanks.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help