I've only thought about this for a couple of minutes but the attached could
work,
where we always ignore SIGPIPE and then convert the EPIPE on stdout to SIGPIPE.
I'll do lots of testing with this and add a new test before pushing,
but it does pass basic tests here:
# ---- put previous exit statuses in prompt
$ PS1="[\[\033[1;31m\]\${PIPESTATUS[@]/#0/\[\033[0m\]"\
"\[\033[1;32m\]0\[\033[1;31m\]}\[\033[0m\]] \w$"
[0] $ printf '%s\n' '#!/bin/sh' 'exit 1' > exit1 && chmod a+x exit1
# ---- we now diagnose these failures always
[0] $ src/sort -S 100K --compress-program=./exit1 Makefile | head -n1
sort: write failed: /tmp/sortlh70wt: Broken pipe
# ---- normal pipe operation is maintained
[2 0] $ seq 10000 | sort | :
[0 141 0] $