Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parse record error verbiage #175

Open
JarvisVon opened this issue Jun 24, 2024 · 0 comments · May be fixed by #177
Open

Fix parse record error verbiage #175

JarvisVon opened this issue Jun 24, 2024 · 0 comments · May be fixed by #177

Comments

@JarvisVon
Copy link

JarvisVon commented Jun 24, 2024

  • vcfpy version: 0.13.8
  • Python version: 3.12.1
  • Operating System: macOS 14.0

Description

When parsing a file with 9 columns, the 8 required plus an additional FORMAT column, a confusing error is returned of the form "The line contains an invalid number of fields. Was 9 but expected 9".

What I Did

import vcfpy
path = '/path/to/file.vcf'
reader = vcfpy.Reader.from_path(path)
records = []
for record in reader:
  # do work

Stack Trace:
  File "<stdin>", line 1, in <module>
  File "python3.12/site-packages/vcfpy/reader.py", line 175, in __next__
    result = self.parser.parse_next_record()
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "python3.12/site-packages/vcfpy/parser.py", line 804, in parse_next_record
    return self.parse_line(self._read_next_line())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "python3.12/site-packages/vcfpy/parser.py", line 795, in parse_line
    return self._record_parser.parse_line(line)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "python3.12/site-packages/vcfpy/parser.py", line 425, in parse_line
    arr = self._split_line(line_str)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "python3.12/site-packages/vcfpy/parser.py", line 518, in _split_line
    raise exceptions.InvalidRecordException(
vcfpy.exceptions.InvalidRecordException: The line contains an invalid number of fields. Was 9 but expected 9

The fix would be to update line 521 in vcfpy/parser.py to use self.expected_fields as opposed to 9 + len(self.samples.names), as this distinction is already handled when 9 + len(self.samples.names) is set at lines 399-402 and is used as the error criteria in parser.py line 513

@JarvisVon JarvisVon changed the title Confusing error message in "The line contains an invalid number of fields. Was 9 but expected 9" Fix parse record error verbiage Jun 24, 2024
@JarvisVon JarvisVon linked a pull request Jun 24, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant