Both CLIs panic with exit code 101 when the reader of their standard output closes it early, as head,
grep -m, less or a Python subprocess reading only the first lines do (abridged):
thread 'main' panicked at library/std/src/io/stdio.rs:1166:9:
failed printing to stdout: Broken pipe (os error 32)
In a shell pipeline with set -o pipefail, or in a script that checks return codes, this turns
rdocx text file.docx | head -1 into a failure. The usual fix is to treat BrokenPipe on stdout as a
normal end (exit 0, or 141 like a process killed by SIGPIPE) rather than a panic, in every subcommand
that prints, --json output included. #73 turned a CLI panic on the input side into an error; this one is
on the output side.
python3 - <<'PY'
from docx import Document
from pptx import Presentation
d = Document()
for i in range(20000):
d.add_paragraph("Line %d, lorem ipsum dolor sit amet." % i)
d.save("bp.docx")
p = Presentation()
for i in range(300):
s = p.slides.add_slide(p.slide_layouts[1]); s.shapes.title.text = "Slide %d " % i + "lorem ipsum dolor sit amet " * 20
p.save("bp.pptx")
PY
rdocx text bp.docx | head -1 > /dev/null; echo "rdocx text | head -1 -> exit ${PIPESTATUS[0]}"
rpptx text bp.pptx | head -1 > /dev/null; echo "rpptx text | head -1 -> exit ${PIPESTATUS[0]}"
rdocx text bp.docx > /dev/null; echo "rdocx text > /dev/null -> exit $?"
rdocx text | head -1 -> exit 101
rpptx text | head -1 -> exit 101
rdocx text > /dev/null -> exit 0
(The output has to exceed the pipe buffer for the write to fail, hence the size of the fixtures: with
2,000 paragraphs, about 77 kB of text, rdocx already panics on Linux but not on macOS.)
Environment: main at 9a7ed714 (S75), release build, linux x86_64 and macOS arm64.
Both CLIs panic with exit code 101 when the reader of their standard output closes it early, as
head,grep -m,lessor a Pythonsubprocessreading only the first lines do (abridged):In a shell pipeline with
set -o pipefail, or in a script that checks return codes, this turnsrdocx text file.docx | head -1into a failure. The usual fix is to treatBrokenPipeon stdout as anormal end (exit 0, or 141 like a process killed by SIGPIPE) rather than a panic, in every subcommand
that prints,
--jsonoutput included. #73 turned a CLI panic on the input side into an error; this one ison the output side.
(The output has to exceed the pipe buffer for the write to fail, hence the size of the fixtures: with
2,000 paragraphs, about 77 kB of text,
rdocxalready panics on Linux but not on macOS.)Environment:
mainat9a7ed714(S75), release build, linux x86_64 and macOS arm64.