Skip to content

inputfile.last_line is not always available #1220

@oliver-s-lee

Description

@oliver-s-lee

LogFileParser expects its inputfile to support last_line, but this is only exposed by the custom FileWrapper class which is not used for all input types.

For a concrete example, any files parsed with --multi (which is common for Turbomole etc) are not wrapped, and LogFileParser will crash if a parsing error occurs.

Attempting to read ./basis and water.log
[Turbomole ['./basis', 'water.log'] ERROR] Encountered error when parsing.
Traceback (most recent call last):
  File "/home/oliver/dev/cclib/cclib Src/cclib/parser/logfileparser.py", line 337, in parse
    self.extract(inputfile, line)
  File "/home/oliver/dev/cclib/cclib Src/cclib/parser/turbomoleparser.py", line 795, in extract
    self.iter_one_elec_energy.append(utils.float(info[2]))
  File "/home/oliver/dev/cclib/cclib Src/cclib/parser/utils.py", line 77, in float
    return _BUILTIN_FLOAT(number.replace("D", "E"))
ValueError: could not convert string to float: 's'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/oliver/.local/bin/ccget", line 8, in <module>
    sys.exit(ccget())
  File "/home/oliver/dev/cclib/cclib Src/cclib/scripts/ccget.py", line 178, in ccget
    data = ccread(filename, **kwargs)
  File "/home/oliver/dev/cclib/cclib Src/cclib/io/ccio.py", line 174, in ccread
    return log.parse()
  File "/home/oliver/dev/cclib/cclib Src/cclib/parser/logfileparser.py", line 343, in parse
    self.logger.error(f"Last line read: {inputfile.last_line}")
AttributeError: 'FileInput' object has no attribute 'last_line'

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions