Fortran-FOSS-Programmers / ford

Automatically generates FORtran Documentation from comments within the code.
https://forddocs.readthedocs.io
GNU General Public License v3.0
402 stars 131 forks source link

Ford crashes even with --force when `e.args` tuple has zero length in `fortran_project.Project.__init__` #618

Closed Liam-Deacon closed 6 months ago

Liam-Deacon commented 6 months ago

I get an (edge-case?) failure when attempting to process some fortran files that ford doesn't like.

$ ford -d phshift2007 -o ford --extensions '.f90' --force README.md                                                                                                                                                               
ERROR in file 'phsh2wil.for': Unexpected variable in sourcefile 'phsh2wil.for':
        REAL E(401),S(401,15),C(401,15),DEL(15),DELOLD(15)
ERROR in file 'phsh2wil.for': Unexpected variable in sourcefile 'phsh2wil.for':
        REAL DELL(9),delstore(8,401,15)
ERROR in file 'phsh2wil.for': Unexpected variable in sourcefile 'phsh2wil.for':
        INTEGER TLP1
ERROR in file 'phsh2wil.for': Unexpected COMMON statement in sourcefile 'phsh2wil.for':
        COMMON / CM16 / E1, E2, NE, IX,NEUO
ERROR in file 'phsh2wil.for': Unexpected COMMON statement in sourcefile 'phsh2wil.for':
        COMMON / CMRV / R(201), V(201, 15), NR, NL, Z
ERROR in file 'phsh2wil.for': Unexpected COMMON statement in sourcefile 'phsh2wil.for':
        COMMON / CM5 / Y(30,4), F(30,4), ILST
ERROR in file 'phsh2wil.for': Unexpected procedure call in sourcefile 'phsh2wil.for':
        CALL S16
ERROR in file 'phsh2wil.for': END statement outside of any nesting:
        END
⠋ Parsing files         ━━━━━━╸━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━  17% 1/6 -:--:-- 0:00:00 phshift2007/phsh2wil.for
Traceback (most recent call last):
  File "/home/liam/.pyenv/versions/3.11.4/lib/python3.11/site-packages/ford/fortran_project.py", line 178, in __init__
    self._fortran_file(extension, filename, settings)
  File "/home/liam/.pyenv/versions/3.11.4/lib/python3.11/site-packages/ford/fortran_project.py", line 196, in _fortran_file
    new_file = FortranSourceFile(
               ^^^^^^^^^^^^^^^^^^
  File "/home/liam/.pyenv/versions/3.11.4/lib/python3.11/site-packages/ford/sourceform.py", line 1568, in __init__
    super().__init__(source, "")
  File "/home/liam/.pyenv/versions/3.11.4/lib/python3.11/site-packages/ford/sourceform.py", line 862, in __init__
    self._cleanup()
  File "/home/liam/.pyenv/versions/3.11.4/lib/python3.11/site-packages/ford/sourceform.py", line 1134, in _cleanup
    raise NotImplementedError()
NotImplementedError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/liam/.pyenv/versions/3.11.4/bin/ford", line 8, in <module>
    sys.exit(run())
             ^^^^^
  File "/home/liam/.pyenv/versions/3.11.4/lib/python3.11/site-packages/ford/__init__.py", line 489, in run
    main(proj_data, proj_docs)
  File "/home/liam/.pyenv/versions/3.11.4/lib/python3.11/site-packages/ford/__init__.py", line 411, in main
    project = ford.fortran_project.Project(proj_data)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/liam/.pyenv/versions/3.11.4/lib/python3.11/site-packages/ford/fortran_project.py", line 185, in __init__
    warn(f"Error parsing {relative_path}.\n\t{e.args[0]}")
                                              ~~~~~~^^^
IndexError: tuple index out of range

The secondary exception handling the first fails due to a slight issue with the logic when handling empty tuples for e.args:

https://github.com/Fortran-FOSS-Programmers/ford/blob/809aa101515e2acfce284ddf87176e1580b966ce/ford/fortran_project.py#L181-L185

This could be easily fixed by having a quick check:

warn(f"Error parsing {relative_path}.\n\t{e.args if len(e.args) == 0 else e.args[0]}")
Liam-Deacon commented 6 months ago

Note this issue is mentioned within the discussion of https://github.com/Fortran-FOSS-Programmers/ford/issues/475#issue-1570309873