modelmat / sphinxcontrib-drawio

Sphinx extension for including draw.io files.
MIT License
39 stars 17 forks source link

Getting random failures that have an empty stderr/stdout #69

Closed jdillard closed 2 years ago

jdillard commented 2 years ago

Occasionally we get a random failure (random in that we can re-run the build and it won't fail the next time), but the [stderr] and [stdout] is empty making it tricky to troubleshoot.

DrawIO Error:
draw.io (/opt/drawio/drawio --export --crop --page-index 0 --scale 1.0 --transparent --format png --output /path/to/image.png /path/to/image.drawio --no-sandbox) exited with error:
[stderr]
b''
[stdout]
b''

It looks like that output comes from these lines of code, do you think the reason they are blank has something to do with the subprocess.run() arguments or subprocess.CalledProcessError? I'm mainly trying to figure out what might be a good place to troubleshoot to find if there is stderr/stdout that is getting lost somewhere.

(Sorry about opening all these issues recently, I love this extension!)

modelmat commented 2 years ago

Hmm, I'm very certain that's the correct way to get output from subprocess.

Python 3.10.4 (main, Mar 25 2022, 00:00:00) [GCC 11.2.1 20220127 (Red Hat 11.2.1-9)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.run("echo hi && false", stderr=subprocess.PIPE, stdout=subprocess.PIPE, check=True, shell=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python3.10/subprocess.py", line 524, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command 'echo hi && false' returned non-zero exit status 1.
>>> try:
...     subprocess.run("echo hi && false", stderr=subprocess.PIPE, stdout=subprocess.PIPE, check=True, shell=True)
... except subprocess.CalledProcessError as exc:
...     print(exc.stderr, exc.stdout)
... 
b'' b'hi\n'
>>> 

The exc.stderr and exc.stdout are the same values you would get from the return of subprocess.run() (i.e., in this extension's code, ret, and those get grabbed by the subprocess.PIPE).

I wouldn't entirely be surprised if this is an issue with the draw.io application, though.

To narrow that down, you could potentially try running the subprocess.run() of that specific example in a loop and see if the fails doing that? (I am meaning, rip the code that handles running the draw.io file, and run it outside the context of it being an extension).

Sorry for taking a while to respond, I tend to forget to check github notifications. I'm glad some people are finding this useful -- the usecase I originally made it for wouldn't work, so it kinda wasn't too useful for me :upside_down_face:

jdillard commented 2 years ago

Not worries at all! Sorry for taking so long to get back to you, but I was finally able to figure out that I'm getting a return code of 7, or a SIGBUS error, so definitely something upstream somewhere. It looks like drawio has been doing some stability work in recent releases, so I'll try upgrading soon. I made https://github.com/modelmat/sphinxcontrib-drawio/pull/70 to add the exc.returncode to the error output, so that should cover all the potential error bases.