invoice-x / factur-x-ng

Python lib for Factur-X, the e-invoicing standard for France and Germany
Other
34 stars 8 forks source link

Proper error message when PDF doesn't exist #19

Closed duskybomb closed 6 years ago

duskybomb commented 6 years ago

If there is no pdf named inv2.pdf in the directory

  File "my_file.py", line 4, in <module>
    factx = FacturX('inv2.pdf')
  File "D:\GSoC\factur-x\facturx\facturx.py", line 59, in __init__
    xml = self._xml_from_file(pdf_file)
  File "D:\GSoC\factur-x\facturx\facturx.py", line 80, in _xml_from_file
    pdf = PdfFileReader(pdf_file)
  File "D:\Projects\Invoice2data-GUI\venv\lib\site-packages\PyPDF2\pdf.py", line 1084, in __init__
    self.read(stream)
  File "D:\Projects\Invoice2data-GUI\venv\lib\site-packages\PyPDF2\pdf.py", line 1697, in read
    line = self.readNextEndLine(stream)
  File "D:\Projects\Invoice2data-GUI\venv\lib\site-packages\PyPDF2\pdf.py", line 1937, in readNextEnd
Line
    raise utils.PdfReadError("Could not read malformed PDF file")
PyPDF2.utils.PdfReadError: Could not read malformed PDF file
m3nu commented 6 years ago

I'm aware. The sample code was just a sample.

There should still a better error message when the input file doesn't exist.

m3nu commented 6 years ago

As I said there need to be some checks to see:

duskybomb commented 6 years ago

My observations:

Hence I added a commit (#18) to raise FileNotFoundError in second condition: isinstance(pdf_invoice, str)

m3nu commented 6 years ago

Cool. To put the icing on the cake you could also make a test that triggers this exception. Would be a good habit to always do feature + test together. Else tests generally get neglected.