ngs icon indicating copy to clipboard operation
ngs copied to clipboard

$(seq 1000000 | head -2)

Open ilyash-b opened this issue 5 years ago • 9 comments

Right now NGS will throw an exception because the first process ended with signal (SIGPIPE). Rethink the behaviour and error detection design.

ilyash-b avatar Oct 05 '19 11:10 ilyash-b

Interestingly enough, analogous bash also fails in the same manner:

$ bash -c 'set -eo pipefail; seq 1000000 | head -2; echo OK'; echo $?
1
2
141

ilyash-b avatar Oct 05 '19 11:10 ilyash-b

Probably SIGPIPE should be excluded when considering which commands have failed

ilyash-b avatar Oct 05 '19 11:10 ilyash-b

Same issue in Elvish - https://github.com/elves/elvish/issues/952

ilyash avatar Apr 04 '21 09:04 ilyash

FWIW Oil has a run builtin which is used to tweak exit codes. This comes up in a couple places:

  • grep can return 0, 1, or 2. That's "found", "not found", or "error".
  • this SIGPIPE problem. For this we have run --status-ok SIGPIPE printf ... | head .

From:

https://old.reddit.com/r/bash/comments/mivbcm/the_set_o_pipefail_is_not_a_best_practice/gtefb4a/

andychu avatar Apr 05 '21 01:04 andychu

FWIW Oil has a run builtin which is used to tweak exit codes. This comes up in a couple places:

* `grep` can return 0, 1, or 2.  That's "found", "not found", or "error".

What's the default behavior for grep exiting with 1?

--allow-status-01 is the related switch? How about other exit codes which I want to express "are OK"? Do I use --assign-status and then check or --status-ok also handles exit codes, not just signals (did not find non-SIGPIPE examples) ?

* this SIGPIPE problem.  For this we have `run --status-ok SIGPIPE printf ... | head` .

From:

https://old.reddit.com/r/bash/comments/mivbcm/the_set_o_pipefail_is_not_a_best_practice/gtefb4a/

ilyash avatar Apr 05 '21 09:04 ilyash

Yup, that's the flag for grep. There's a long thread about it here where we went through almost all the names possible :)

https://oilshell.zulipchat.com/#narrow/stream/121540-oil-discuss/topic/status.20builtin.20proposal

And yes if you want more complicated logic, you use --assign-status, and then use a normal shell case statement on the var:

run --assign-status :st -- cc myfile.cc

case $st {
  (0) echo zero ;;
  (1) echo one ;;
}

Oil allows braces, but in shell that's just:

case $st in
  (0) echo zero ;;
  (1) echo one ;;
esac

andychu avatar Apr 05 '21 09:04 andychu

I came up with an imperfect detection mechanism, thought my fellow shell designers might be interested: https://github.com/elves/elvish/issues/952#issuecomment-816277862

xiaq avatar Apr 08 '21 22:04 xiaq

I came up with an imperfect detection mechanism, thought my fellow shell designers might be interested: elves/elvish#952 (comment)

Thanks! I'll take a look (I see there is a bit of discussion happened)

ilyash-b avatar Apr 09 '21 10:04 ilyash-b

Note: elvish got this solved. Todo: take a look and most likely adopt the solution

ilyash avatar Jul 20 '21 05:07 ilyash