sourcery-ai / sourcery

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

When Sourcery rotated its log file it failed with a `PermissionError` #252

Closed unights closed 2 years ago

unights commented 2 years ago

Issue description or question

Every time I type "from XXX import", such as "from time import", I get an error report from pycharm. The following is a detailed error report. And is there any way to fix it?

java.lang.IllegalStateException: Missing header Content-Length in input "--- Logging error ---
Traceback (most recent call last):
  File "C:\Users\username\AppData\Roaming\JETBRA~1\PYCHAR~1.1\plugins\sourcery\SOURCE~1\install\win\logging\handlers.py", line 74, in emit
  File "C:\Users\username\AppData\Roaming\JETBRA~1\PYCHAR~1.1\plugins\sourcery\SOURCE~1\install\win\logging\handlers.py", line 177, in doRollover
  File "C:\Users\username\AppData\Roaming\JETBRA~1\PYCHAR~1.1\plugins\sourcery\SOURCE~1\install\win\logging\handlers.py", line 115, in rotate
PermissionError: [WinError 32] 另一个程序正在使用此文件,进程无法访问。: 'C:\\Users\\username\\AppData\\Roaming\\sourcery\\sourcery.log' -> 'C:\\Users\\username\\AppData\\Roaming\\sourcery\\sourcery.log.1'
Call stack:
  File "C:\Users\username\AppData\Roaming\JETBRA~1\PYCHAR~1.1\plugins\sourcery\SOURCE~1\install\win\binary\protocol\server.py", line 150, in aio_readline
  File "C:\Users\username\AppData\Roaming\JETBRA~1\PYCHAR~1.1\plugins\sourcery\SOURCE~1\install\win\logging\__init__.py", line 1434, in debug
  File "C:\Users\username\AppData\Roaming\JETBRA~1\PYCHAR~1.1\plugins\sourcery\SOURCE~1\install\win\logging\__init__.py", line 1589, in _log
  File "C:\Users\username\AppData\Roaming\JETBRA~1\PYCHAR~1.1\plugins\sourcery\SOURCE~1\install\win\logging\__init__.py", line 1599, in handle
  File "C:\Users\username\AppData\Roaming\JETBRA~1\PYCHAR~1.1\plugins\sourcery\SOURCE~1\install\win\sentry_sdk\integrations\logging.py", line 86, in sentry_patched_callhandlers
Message: 'Content length: %d'
Arguments: (4075,)
--- Logging error ---
Traceback (most recent call last):
  File "C:\Users\username\AppData\Roaming\JETBRA~1\PYCHAR~1.1\plugins\sourcery\SOURCE~1\install\win\logging\handlers.py", line 74, in emit
  File "C:\Users\username\AppData\Roaming\JETBRA~1\PYCHAR~1.1\plugins\sourcery\SOURCE~1\install\win\logging\handlers.py", line 177, in doRollover
  File "C:\Users\username\AppData\Roaming\JETBRA~1\PYCHAR~1.1\plugins\sourcery\SOURCE~1\install\win\logging\handlers.py", line 115, in rotate
PermissionError: [WinError 32] 另一个程序正在使用此文件,进程无法访问。: 'C:\\Users\\username\\AppData\\Roaming\\sourcery\\sourcery.log' -> 'C:\\Users\\username\\AppData\\Roaming\\sourcery\\sourcery.log.1'
Call stack:
  File "C:\Users\username\AppData\Roaming\JETBRA~1\PYCHAR~1.1\plugins\sourcery\SOURCE~1\install\win\binary\protocol\server.py", line 168, in aio_readline
  File "C:\Users\username\AppData\Roaming\JETBRA~1\PYCHAR~1.1\plugins\sourcery\SOURCE~1\install\win\binary\protocol\jsonrpc_protocol.py", line 200, in data_received
  File "C:\Users\username\AppData\Roaming\JETBRA~1\PYCHAR~1.1\plugins\sourcery\SOURCE~1\install\win\binary\protocol\jsonrpc_protocol.py", line 126, in _procedure_handler
  File "C:\Users\username\AppData\Roaming\JETBRA~1\PYCHAR~1.1\plugins\sourcery\SOURCE~1\install\win\binary\protocol\jsonrpc_protocol.py", line 105, in _handle_request
  File "C:\Users\username\AppData\Roaming\JETBRA~1\PYCHAR~1.1\plugins\sourcery\SOURCE~1\install\win\binary\protocol\jsonrpc_protocol.py", line 68, in _execute_request
  File "C:\Users\username\AppData\Roaming\JETBRA~1\PYCHAR~1.1\plugins\sourcery\SOURCE~1\install\win\binary\protocol\jsonrpc_protocol.py", line 80, in _execute_handler
  File "C:\Users\username\AppData\Roaming\JETBRA~1\PYCHAR~1.1\plugins\sourcery\SOURCE~1\install\win\binary\protocol\decorators.py", line 52, in handler
  File "C:\Users\username\AppData\Roaming\JETBRA~1\PYCHAR~1.1\plugins\sourcery\SOURCE~1\install\win\logging\__init__.py", line 1434, in debug
  File "C:\Users\username\AppData\Roaming\JETBRA~1\PYCHAR~1.1\plugins\sourcery\SOURCE~1\install\win\logging\__init__.py", line 1589, in _log
  File "C:\Users\username\AppData\Roaming\JETBRA~1\PYCHAR~1.1\plugins\sourcery\SOURCE~1\install\win\logging\__init__.py", line 1599, in handle
  File "C:\Users\username\AppData\Roaming\JETBRA~1\PYCHAR~1.1\plugins\sourcery\SOURCE~1\install\win\sentry_sdk\integrations\logging.py", line 86, in sentry_patched_callhandlers
Message: '%s -> %s'
Arguments: ('refactor', {})
--- Logging error ---
Traceback (most recent call last):
  File "C:\Users\username\AppData\Roaming\JETBRA~1\PYCHAR~1.1\plugins\sourcery\SOURCE~1\install\win\sourcery\code\source_parser.py", line 112, in get_qualified_imports_analysis
  File "C:\Users\username\AppData\Roaming\JETBRA~1\PYCHAR~1.1\plugins\sourcery\SOURCE~1\install\win\sourcery\ast\nodes.py", line 112, in parse
  File "C:\Users\username\AppData\Roaming\JETBRA~1\PYCHAR~1.1\plugins\sourcery\SOURCE~1\install\win\sourcery\code\tree_sitter\parser.py", line 45, in parse_source_code_to_ast
  File "C:\Users\username\AppData\Roaming\JETBRA~1\PYCHAR~1.1\plugins\sourcery\SOURCE~1\install\win\ast.py", line 50, in parse
  File "<unknown>", line 6
    from time import
                      ^
SyntaxError: invalid syntax

"
    at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.listen(StreamMessageProducer.java:91)
    at org.eclipse.lsp4j.jsonrpc.json.ConcurrentMessageProcessor.run(ConcurrentMessageProcessor.java:113)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:829)

Sourcery Version

Sourcery v0.12.3

Code editor or IDE name and version

Pycharm v2022.1.3 #PY-221.5921.27

OS name and version

Windows 10

brendanator commented 2 years ago

It looks like there is something locking this file C:\Users\username\AppData\Roaming\sourcery\sourcery.log.1.

See this stackoverflow answer on PermissionError [WinError 32].

You may be able to fix this just by restarting your computer, or finding out which program is locking that file and closing it.

I've added a recovery mechanism for this in the next release too

LucaAust commented 2 years ago

Did you use sourcery with PyCharm and VSCode at the same time? I figured out that they both use the same logs, so they block each other.

I think it would be nice if logs had different file names depending on the used IDE.

Hellebore commented 2 years ago

Resolved with new release.