From 6ff749e62652103b3ab84ef145691602ed6e0fea Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Thu, 11 Feb 2021 17:01:39 +0000 Subject: Add helpful error messages on loopwhilex { block } (and ifte too) --- src/execline/ifte.c | 8 +++++++- src/execline/loopwhilex.c | 9 ++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/execline/ifte.c b/src/execline/ifte.c index d263a4a..1412bf0 100644 --- a/src/execline/ifte.c +++ b/src/execline/ifte.c @@ -1,5 +1,6 @@ /* ISC license. */ +#include #include #include @@ -41,7 +42,12 @@ int main (int argc, char const **argv, char const *const *envp) if (argc1 + argc2 + 2 >= argc) strerr_dief1x(100, "empty command-if") ; pid = el_spawn0(argv[argc1 + argc2 + 2], argv + argc1 + argc2 + 2, envp) ; - if (!pid) strerr_diefu2sys(111, "spawn ", argv[argc1 + argc2 + 2]) ; + if (!pid) + { + if (errno == ENOENT && argv[argc1 + argc2 + 2][0] == ' ') + strerr_diefu3x(111, "spawn ", argv[argc1 + argc2 + 2], ": name begins with a space, are you trying to spawn a block as your command-if?") ; + else strerr_diefu2sys(111, "spawn ", argv[argc1 + argc2 + 2]) ; + } if (wait_pid(pid, &wstat) == -1) strerr_diefu2sys(111, "wait for ", argv[argc1 + argc2 + 2]) ; if (!flagnormalcrash && WIFSIGNALED(wstat)) diff --git a/src/execline/loopwhilex.c b/src/execline/loopwhilex.c index 93a71e0..5add5e5 100644 --- a/src/execline/loopwhilex.c +++ b/src/execline/loopwhilex.c @@ -1,5 +1,7 @@ /* ISC license. */ +#include + #include #include #include @@ -58,7 +60,12 @@ int main (int argc, char const *const *argv, char const *const *envp) while (cont) { pid_t pid = el_spawn0(argv[0], argv, envp) ; - if (!pid) strerr_diefu2sys(111, "spawn ", argv[0]) ; + if (!pid) + { + if (errno == ENOENT && argv[0][0] == ' ') + strerr_diefu3x(111, "spawn ", argv[0], ": name begins with a space, are you trying to spawn a block as your loop body?") ; + else strerr_diefu2sys(111, "spawn ", argv[0]) ; + } if (wait_pid(pid, &wstat) < 0) strerr_diefu1sys(111, "wait_pid") ; cont = not != isok(okcodes, nbc, wait_estatus(wstat)) ; } -- cgit v1.2.3