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

Report data file errors in more detail #1782

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

bartfeenstra
Copy link

@bartfeenstra bartfeenstra commented May 13, 2024

This PR fixes #1781

Changes

  • Introduce NoDataError subclasses for specific purposes
    • Factory methods to construct helpful messages, because it keeps all the default behavior around assumptions of exceptions just having a single string argument working (it gets funky when pickling and what not, so I tend to take this approach)
  • When possible, suggest that the user runs the combine command
  • All critical (albeit sometimes seemingly trivial) bits are now centralized, e.g. no more duplication of messages. This makes it easier to keep everything in sync and improve on.

@bartfeenstra bartfeenstra marked this pull request as draft May 13, 2024 16:18
@bartfeenstra bartfeenstra force-pushed the detailed-data-file-error-reporting branch from 4c63e61 to 49fcc01 Compare May 13, 2024 18:26
@bartfeenstra bartfeenstra marked this pull request as ready for review May 13, 2024 18:26
@bartfeenstra bartfeenstra force-pushed the detailed-data-file-error-reporting branch 2 times, most recently from 8cdb7d8 to a6beae3 Compare May 13, 2024 21:07
@nedbat
Copy link
Owner

nedbat commented May 15, 2024

Thanks for doing this. I would like to include the "coverage combine" message only if there are combinable data files. I've included other comments in the diff.

coverage/cmdline.py Outdated Show resolved Hide resolved
for filename in combinable_files(data_file):
print("-----")
debug_data_file(filename)
with suppress(NoDataFilesFoundError):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to suppress this error here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not, but I tried to limit how many outputs I changed. Would you like this to display a friendly error instead?

coverage/data.py Outdated Show resolved Hide resolved
coverage/exceptions.py Outdated Show resolved Hide resolved
coverage/exceptions.py Outdated Show resolved Hide resolved
coverage/exceptions.py Outdated Show resolved Hide resolved
@@ -317,7 +317,9 @@ def report(self, morfs: Iterable[TMorf] | None) -> float:
file_be_gone(os.path.join(self.directory, ftr.html_filename))

if not have_data:
raise NoDataError("No data to report.")
raise DataFileOrDirectoryNotFoundError.new_for_data_file_or_directory(
os.path.dirname(self.coverage.get_data().base_filename())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to think through whether the message here is correct. Is it always that the file doesn't exist?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good that the exceptions centralize the messages, but everywhere this exception is created it uses the same fairly complex expression. Can we centralize that as well?

with pytest.raises(
NoDataError,
match=(
r"^The data file or directory `(.+?)` could not be found\. Perhaps `coverage "
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"The data file or directory" seems odd to me. Don't we know whether we are expecting a file or directory?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These results depend on the paths entered in the CLI. As far as I understand the code these are allowed to be data file paths or paths to directories containing data files. If the path does not exist, I'm not sure we would know if the user meant a file or a directory.

@bartfeenstra bartfeenstra force-pushed the detailed-data-file-error-reporting branch from a6beae3 to 8bf5006 Compare May 16, 2024 18:23
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.

Add a hint that coverage combine might be needed
2 participants