jendrikseipp / vulture

Find dead Python code
MIT License
3.38k stars 148 forks source link

UnicodeEncodeError in core.py #299

Closed milanbalazs closed 1 year ago

milanbalazs commented 1 year ago

I got UnicodeEncodeError exception during the Vulture analysis.

Traceback:

Traceback (most recent call last):
    File "/ws/venv3_x/bin/vulture", line 8, in <module>
      sys.exit(main())
    File "/ws/venv3_x/lib/python3.6/site-packages/vulture/core.py", line 710, in main
      make_whitelist=config["make_whitelist"],
    File "/ws/venv3_x/lib/python3.6/site-packages/vulture/core.py", line 334, in report
      else item.get_report(add_size=sort_by_size)
  UnicodeEncodeError: 'latin-1' codec can't encode characters in position 84-90: ordinal not in range(256)

My command:

vulture "--exclude" "venv2/,venv3_*,*update_repo.py" "."

Used vulture version in requirements.txt file:

Used Python version:

It's possible that my codebase contains special characters but it's hard to debug it because I analyze ~1000 Python files in the same time (And the provided Exception doesn't contain any reference for the problematic file).

I think it would be nice to improve the Encoding in the core.py or at least handle the exception and throw a more talkative exception (perhaps with the name/path of the problematic file)

Thank you in advance!

milanbalazs commented 1 year ago

I have changed the venv3_* pattern to *venv3_* in the --exclude parameter and now the analysis works as expected. I have removed all non-ascii characters from my code-base so in my opinion the faulty file is in the Virtual Environment.

On the other hand, I still think the Exception should me more specific/talkative and the error should be handled.

jendrikseipp commented 1 year ago

Thanks for the report! I agree that the error message should include the file name. Would you care to prepare a PR for this?

milanbalazs commented 1 year ago

Sure, I will create a PR for it!