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

add line number to error messages #39

Merged
merged 1 commit into from
Feb 3, 2023

Conversation

matt-telstra
Copy link
Collaborator

I just got an error when parsing a particular file. I'm not yet sure whether the file is invalid, or there's a bug in this library.

It would be nice if the error messages mentioned the line number. My particular error was pretty deep, so I've just added a try except that catches and rethrows errors.

So the original error I had was:

Traceback (most recent call last):
  File "/Users/matthew/Documents/nem12/nemreader/nem_reader.py", line 272, in parse_nem12_rows
    readings[nmi_d.nmi][nmi_d.nmi_suffix][-1] = update_reading_events(
  File "/Users/matthew/Documents/nem12/nemreader/nem_reader.py", line 504, in update_reading_events
    t_start=readings[i].t_start,
IndexError: list index out of range

Now it looks like:

Traceback (most recent call last):
  File "/Users/matthew/Documents/nem12/nemreader/nem_reader.py", line 272, in parse_nem12_rows
    readings[nmi_d.nmi][nmi_d.nmi_suffix][-1] = update_reading_events(
  File "/Users/matthew/Documents/nem12/nemreader/nem_reader.py", line 504, in update_reading_events
    t_start=readings[i].t_start,
IndexError: list index out of range

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/matthew/Documents/nem12/main.py", line 9, in <module>
    df = nf.get_data_frame()
  File "/Users/matthew/Documents/nem12/nemreader/nem_reader.py", line 124, in get_data_frame
    nd = self.nem_data()
  File "/Users/matthew/Documents/nem12/nemreader/nem_reader.py", line 109, in nem_data
    reads = self.parse_nem_file(nmi_file)
  File "/Users/matthew/Documents/nem12/nemreader/nem_reader.py", line 80, in parse_nem_file
    return parse_nem12_rows(reader, file_name=nem_file)
  File "/Users/matthew/Documents/nem12/nemreader/nem_reader.py", line 285, in parse_nem12_rows
    raise ValueError(f"Unable to parse row {row_num}") from e
ValueError: Unable to parse line 3360

Which I think makes it easier to try to see what went wrong by looking at the raw file..

@aguinane aguinane merged commit b21d4a8 into aguinane:master Feb 3, 2023
@aguinane
Copy link
Owner

aguinane commented Feb 3, 2023

Thanks, definitely seems like it would be helpful for large files.

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 this pull request may close these issues.

2 participants