AlJohri / docx2pdf

MIT License
506 stars 96 forks source link

exit() call in library code not working #6

Closed jack-rory-staunton closed 4 years ago

jack-rory-staunton commented 4 years ago

From jupyter the code breaks at line 73

exit(1)

with the following traceback:

NameError Traceback (most recent call last)

in ----> 1 convert('./BAAM_raw/docx/', './BAAM_raw/docx/pdf/') /usr/local/lib/python3.7/site-packages/docx2pdf/__init__.py in convert(input_path, output_path, keep_active) 102 paths = resolve_paths(input_path, output_path) 103 if sys.platform == "darwin": --> 104 return macos(paths, keep_active) 105 elif sys.platform == "win32": 106 return windows(paths, keep_active) /usr/local/lib/python3.7/site-packages/docx2pdf/__init__.py in macos(paths, keep_active) 70 elif msg["result"] == "error": 71 print(msg) ---> 72 exit(1) 73 74 NameError: name 'exit' is not defined I tried editing the import with: from sys import exit but this does not change anything.
AlJohri commented 4 years ago

thanks for reporting @jack-rory-staunton. I'll push a fix soon

AlJohri commented 4 years ago

@jack-rory-staunton I just pushed version 0.1.7, can you try it out?

jack-rory-staunton commented 4 years ago

thanks for your quick reaction - I'm running it now, I will let you know how it goes!

jack-rory-staunton commented 4 years ago

I had previously edited that line to sys.exit(1) and it didn't fix the issue. Using 0.1.7 I get the same error (below). I think iPython handles quit/exit/sys.exit somehow differently to Python and a different workaround is required.


SystemExit Traceback (most recent call last)

in ----> 1 convert('./BAAM_raw/', './BAAM_raw/') /usr/local/lib/python3.7/site-packages/docx2pdf/__init__.py in convert(input_path, output_path, keep_active) 102 paths = resolve_paths(input_path, output_path) 103 if sys.platform == "darwin": --> 104 return macos(paths, keep_active) 105 elif sys.platform == "win32": 106 return windows(paths, keep_active) /usr/local/lib/python3.7/site-packages/docx2pdf/__init__.py in macos(paths, keep_active) 70 elif msg["result"] == "error": 71 print(msg) ---> 72 sys.exit(1) 73 74 SystemExit: 1
jack-rory-staunton commented 4 years ago

In any case, when using the convert() function on a whole directory, it would be nice if there was a way to skip over any files that throw such exceptions (e.g. wrap in a try/except).

jack-rory-staunton commented 4 years ago

I tried processing the same file using the CLI and get this:

| => docx2pdf ./ ./ 0%| | 0/2 [00:00<?, ?it/s]{'input': '/Users/jrs/Documents/GitHub/nndata-research-bundle/services/BAAM_raw/ASED draft BAA 7.20.2017.docx', 'output': '/Users/jrs/Documents/GitHub/nndata-research-bundle/services/BAAM_raw/ASED draft BAA 7.20.2017.pdf', 'result': 'error', 'error': 'Error: Message not understood.'}

AlJohri commented 4 years ago

Got it. We can make that happen.

On Tue, Apr 28, 2020 at 9:30 AM Jack Rory Staunton notifications@github.com wrote:

I tried processing the same file using the CLI and get this:

| => docx2pdf ./ ./ 0%| | 0/2 [00:00<?, ?it/s]{'input': '/Users/jrs/Documents/GitHub/nndata-research-bundle/services/BAAM_raw/ASED draft BAA 7.20.2017.docx', 'output': '/Users/jrs/Documents/GitHub/nndata-research-bundle/services/BAAM_raw/ASED draft BAA 7.20.2017.pdf', 'result': 'error', 'error': 'Error: Message not understood.'}

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/AlJohri/docx2pdf/issues/6#issuecomment-620609042, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAVJFTBZBQYYRCH5ELDFMZ3RO3K65ANCNFSM4MSEER2Q .

reisner commented 3 years ago

I also get the Error: Message not understood. -- is there any way to figure out what is causing this in the input file?

asapsmc commented 1 year ago

I'm also getting this error. Is there any news about this?