diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2020-06-05 20:06:06 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2020-06-08 16:50:24 +0300 |
commit | 7fdc55efe423f58e5ce03e7f758ace6443800b7a (patch) | |
tree | abca1c7f4f9ebcf1fbc292ff76469f72ded6ee77 /libbuild2/script/run.cxx | |
parent | 10a4ed7c470d3fed8e2bb6b2089de68c61f9064b (diff) |
Cleanup script command failure diagnostics
Diffstat (limited to 'libbuild2/script/run.cxx')
-rw-r--r-- | libbuild2/script/run.cxx | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/libbuild2/script/run.cxx b/libbuild2/script/run.cxx index 5629a15..46c061c 100644 --- a/libbuild2/script/run.cxx +++ b/libbuild2/script/run.cxx @@ -939,8 +939,6 @@ namespace build2 env.clean ({cl.type, move (np)}, false); } - bool eq (c.exit.comparison == exit_comparison::eq); - // If stdin file descriptor is not open then this is the first pipeline // command. // @@ -1012,11 +1010,8 @@ namespace build2 if (c.err) fail (ll) << "exit builtin stderr cannot be redirected"; - // We can't make sure that there is no exit code check. Let's, at - // least, check that non-zero code is not expected. - // - if (eq != (c.exit.code == 0)) - fail (ll) << "exit builtin exit code cannot be non-zero"; + if (c.exit) + fail (ll) << "exit builtin exit code cannot be checked"; if (verb >= 2) print_process (process_args ()); @@ -1168,8 +1163,8 @@ namespace build2 if (c.err) fail (ll) << "set builtin stderr cannot be redirected"; - if (eq != (c.exit.code == 0)) - fail (ll) << "set builtin exit code cannot be non-zero"; + if (c.exit) + fail (ll) << "set builtin exit code cannot be checked"; if (verb >= 2) print_process (process_args ()); @@ -1677,8 +1672,7 @@ namespace build2 // If there is no valid exit code available by whatever reason then we // print the proper diagnostics, dump stderr (if cached and not too // large) and fail the whole script. Otherwise if the exit code is not - // correct then we print diagnostics if requested and fail the - // pipeline. + // correct then we print diagnostics if requested and fail the pipeline. // bool valid (exit->normal ()); @@ -1690,7 +1684,11 @@ namespace build2 valid = exit->code () < 256; #endif - success = valid && eq == (exit->code () == c.exit.code); + exit_comparison cmp (c.exit ? c.exit->comparison : exit_comparison::eq); + uint16_t exc (c.exit ? c.exit->code : 0); + + success = valid && + (cmp == exit_comparison::eq) == (exc == exit->code ()); if (!valid || (!success && diag)) { @@ -1710,8 +1708,13 @@ namespace build2 else if (!success) { if (diag) - d << pr << " exit code " << ec << (eq ? " != " : " == ") - << static_cast<uint16_t> (c.exit.code); + { + if (c.exit) + d << pr << " exit code " << ec + << (cmp == exit_comparison::eq ? " != " : " == ") << exc; + else + d << pr << " exited with code " << ec; + } } else assert (false); |