sourcery-ai / sourcery

Instant AI code reviews
https://sourcery.ai
MIT License
1.51k stars 65 forks source link

Consistent complaints regarding not being able to write to log file #324

Closed jackdewinter closed 1 year ago

jackdewinter commented 1 year ago

Checklist

Description

Code snippet that reproduces issue

Command line used:

pipenv run sourcery review pymarkdown\markdown_token.py

Url to file: https://github.com/jackdewinter/pymarkdown/blob/main/pymarkdown/markdown_token.py

Debug Information

IDE Version: Cmd Line, run under pipenv

Sourcery Version: 1.0.4

Operating system and Version: Win10

Extra Info: command line output:

Traceback (most recent call last):
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\logging\handlers.py", line 74, in emit
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\binary\logging.py", line 38, in doRollover
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process:
'C:\\Users\\jack\\AppData\\Local\\sourcery\\sourcery.log'
Call stack:
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\__main__.py", line 410, in <module>
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\click\core.py", line 1128, in __call__
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\click\core.py", line 1055, in main
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\click\core.py", line 1657, in invoke
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\click\core.py", line 1393, in invoke
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\click\core.py", line 759, in invoke
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\__main__.py", line 375, in review
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\binary\command_line_interface.py", line 244, in review
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\binary\command_line_interface.py", line 382, in _review
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\binary\command_line_interface.py", line 690, in _review_one
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\sourcery\engine\refactor.py", line 109, in refactor_functions
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\sourcery\engine\refactor.py", line 359, in _refactor_code_sections
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\sourcery\engine\refactor.py", line 468, in _refactor_code_section
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\sourcery\engine\refactor.py", line 582, in _group_results_combined
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\sourcery\util\exception.py", line 54, in handle_exception
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\logging\__init__.py", line 1512, in exception
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\logging\__init__.py", line 1506, in error
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\logging\__init__.py", line 1624, in _log
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\logging\__init__.py", line 1634, in handle
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\sentry_sdk\integrations\logging.py", line 86, in
sentry_patched_callhandlers
Message: "Failed to unparse refactored code while preserving comments. Proposal IDs: {'remove-unnecessary-cast'}."
Arguments: ()
--- Logging error ---
Traceback (most recent call last):
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\sourcery\code\source_unparser.py", line 220, in format_code
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\black\__init__.py", line 1073, in format_str
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\black\__init__.py", line 1083, in _format_str_once
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\black\parsing.py", line 127, in lib2to3_parse
black.parsing.InvalidInput: Cannot parse: 2:0:     + MarkdownToken._token_indented_code_block

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

Traceback (most recent call last):
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\sourcery\engine\refactor.py", line 568, in _group_results_combined
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\sourcery\engine\refactor.py", line 817, in result_to_recommendation
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\sourcery\engine\refactor.py", line 887, in refactoring_sections
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\sourcery\engine\refactor.py", line 946, in
_create_changed_section_for_functions
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\sourcery\engine\refactor.py", line 959, in
_create_changed_section_for_module
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\sourcery\code\code_section.py", line 45, in unparse
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\sourcery\code\source_unparser.py", line 69, in unparse_source
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\sourcery\ast\unparser.py", line 55, in unparse
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\sourcery\ast\unparser.py", line 123, in visit
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\sourcery\code\source_unparser.py", line 181, in wrapped_visit
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\sourcery\ast\unparser.py", line 398, in visit_functiondef
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\sourcery\code\source_unparser.py", line 162, in _stmt_list
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\sourcery\ast\unparser.py", line 225, in _stmt_list
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\sourcery\ast\unparser.py", line 225, in <listcomp>
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\sourcery\ast\unparser.py", line 123, in visit
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\sourcery\code\source_unparser.py", line 190, in wrapped_visit
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\sourcery\code\source_unparser.py", line 256, in format_code
sourcery.util.exception.SourceryError: (InvalidInput('Cannot parse: 2:0:     + MarkdownToken._token_indented_code_block'), 'Failed
to format code:\n\n')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\binary\logging.py", line 35, in doRollover
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\logging\handlers.py", line 179, in doRollover
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\logging\handlers.py", line 115, in rotate
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process:
'C:\\Users\\jack\\AppData\\Local\\sourcery\\sourcery.log' -> 'C:\\Users\\jack\\AppData\\Local\\sourcery\\sourcery.log.1'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\logging\handlers.py", line 74, in emit
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\binary\logging.py", line 38, in doRollover
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process:
'C:\\Users\\jack\\AppData\\Local\\sourcery\\sourcery.log'
Call stack:
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\__main__.py", line 410, in <module>
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\click\core.py", line 1128, in __call__
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\click\core.py", line 1055, in main
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\click\core.py", line 1657, in invoke
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\click\core.py", line 1393, in invoke
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\click\core.py", line 759, in invoke
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\__main__.py", line 375, in review
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\binary\command_line_interface.py", line 244, in review
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\binary\command_line_interface.py", line 382, in _review
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\binary\command_line_interface.py", line 690, in _review_one
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\sourcery\engine\refactor.py", line 109, in refactor_functions
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\sourcery\engine\refactor.py", line 359, in _refactor_code_sections
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\sourcery\engine\refactor.py", line 468, in _refactor_code_section
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\sourcery\engine\refactor.py", line 582, in _group_results_combined
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\sourcery\util\exception.py", line 54, in handle_exception
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\logging\__init__.py", line 1512, in exception
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\logging\__init__.py", line 1506, in error
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\logging\__init__.py", line 1624, in _log
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\logging\__init__.py", line 1634, in handle
  File "C:\Users\jack\VIRTUA~1\PYMARK~1\lib\SITE-P~1\sourcery\sentry_sdk\integrations\logging.py", line 86, in
sentry_patched_callhandlers
Message: "Failed to unparse refactored code while preserving comments. Proposal IDs: {'remove-unnecessary-cast'}."
Arguments: ()
bm424 commented 1 year ago

Hi @jackdewinter, thanks for sharing this. Looks like there are two bugs here.

  1. Sourcery is trying to create a code change but it's not resulting in correct code - that's what's throwing the initial error.
  2. When we roll over the log file, if a permission error occurs we try to suppress it and just delete the existing file. It looks like on Windows that can also cause a permission error.

I've put in a couple of changes that I hope will fix both of these, they should be available in version 1.0.6. In the meantime, you can try deleting your sourcery log files located in C:\Users\jack\AppData\Local\sourcery\ to see if that helps sourcery to work again.