trlc icon indicating copy to clipboard operation
trlc copied to clipboard

trlc crash when used in pipeline

Open florianschanda opened this issue 6 months ago • 0 comments

In some scenarios, calling TRLC and piping the output to head creates a crash:

$ trlc | head
T foo1 {x = 1}
  ^^^^ ./foo.trlc:2: check warning: potato
T foo10 {x = 1}
  ^^^^^ ./foo.trlc:11: check warning: potato
T foo100 {x = 1}
  ^^^^^^ ./foo.trlc:101: check warning: potato
T foo101 {x = 1}
  ^^^^^^ ./foo.trlc:102: check warning: potato
T foo102 {x = 1}
  ^^^^^^ ./foo.trlc:103: check warning: potato
Traceback (most recent call last):
  <snip>
  File "/home/potato/.local/lib/python3.10/site-packages/trlc/errors.py", line 220, in emit
    print(context[1].replace("\t", " "), msg)
BrokenPipeError: [Errno 32] Broken pipe

You can reproduce this by creating a lot of text, e.g:

package Foo

type T {
  x Integer
}

checks T {
  x == 0, warning "potato"
}

And then generate a body:

echo "package Foo" > foo.trlc
for I in $(seq 1 400); do echo "T foo$I {x = 1}" >> foo.trlc; done

I think the way to deal with this is to rename main (https://github.com/bmw-software-engineering/trlc/blob/9d804f1dfc1e3bb31897429312d70aa0a504ffc6/trlc/trlc.py#L553), and create a new main that just calls it, but also catches BrokenPipeError and quits silently.

florianschanda avatar Aug 13 '24 08:08 florianschanda