guilatrova / tryceratops

A linter to prevent exception handling antipatterns in Python (limited only for those who like dinosaurs).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`PermissionError` on Windows when deleting empty log file

rodrigogiraoserrao opened this issue · comments

On Windows 10 64 bit Python 3.9, running tryceratops displays the violations that tryceratops finds, but then a permission error is thrown when the program tries to delete the .tryceratops-errors.log empty file.

The full traceback follows:

Traceback (most recent call last):
  File "C:\Program Files\Python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\Python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\rodri\AppData\Roaming\Python\Python39\site-packages\tryceratops\__main__.py", line 56, in <module>
    main()
  File "C:\Users\rodri\AppData\Roaming\Python\Python39\site-packages\tryceratops\__main__.py", line 52, in main
    entrypoint()
  File "C:\Users\rodri\AppData\Roaming\Python\Python39\site-packages\click\core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "C:\Users\rodri\AppData\Roaming\Python\Python39\site-packages\click\core.py", line 782, in main
    rv = self.invoke(ctx)
  File "C:\Users\rodri\AppData\Roaming\Python\Python39\site-packages\click\core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Users\rodri\AppData\Roaming\Python\Python39\site-packages\click\core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "C:\Users\rodri\AppData\Roaming\Python\Python39\site-packages\tryceratops\__main__.py", line 47, in entrypoint
    interface.present_and_exit()
  File "C:\Users\rodri\AppData\Roaming\Python\Python39\site-packages\tryceratops\interfaces.py", line 75, in present_and_exit
    self._delete_empty_logs()
  File "C:\Users\rodri\AppData\Roaming\Python\Python39\site-packages\tryceratops\interfaces.py", line 70, in _delete_empty_logs
    os.remove(log_file_path)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\xxx/.tryceratops-errors.log'

tryceratops was invoked with the command python -m tryceratops my_code_file.py.

Nice! Thank you for reporting.
It's curious that Windows allows creating, but not delete ha

I believe tryceratops should try to delete, but ignore the exception in case it fails. What do you think?