How to detect file format errors when running headless. Just hangs.

I am using libreoffice in headless mode to load an RTF file and apply a macro to it. If the RTF file is corrupt then the command just hangs forever with no output. Starting in non-headless mode shows me the error “File format error found at 101,10461(row,col)”.

I’ve tried using the --backtrace switch and installing the gdb file but the resulting log doesn’t tell me anything about the file format error. Plus the libreoffice-gdb package is 600MB. A huge price to pay for a simple error message!

The only solution I currently have is to time out the process and then kill it. This is not a good solution since some valid RTF files I have in some languages take a long time to parse anyway. So I would have to wait a very long time to establish that the reason it is hanging is some unknown error.

Is there any way to detect file format errors when in headless mode?