svaante / dape

Debug Adapter Protocol for Emacs
GNU General Public License v3.0
455 stars 25 forks source link

`error in process filter: Invalid format operation %|` with Python tqdm #58

Closed haditim closed 7 months ago

haditim commented 7 months ago

Hello and thanks for the awesome package which has made my development life much easier. I use dape almost every day. I recently observed two issues with dape-repl buffer when having tqdm in the Python code I am debugging.

I could remove the first issue by:

(add-hook 'dape-repl-mode-hook (lambda () (setq buffer-display-table (make-display-table)) (aset buffer-display-table ?\^M [])))

But had no success fixing the second one. Even doing the following changed nothing

(add-hook 'dape-repl-mode-hook (lambda () (remove-hook 'window-buffer-change-functions 'dape--info-buffer-change-fn)))

To reproduce, create the following Python script and run dape using debugpy:

from tqdm.auto import tqdm
import time

for item in tqdm(range(100), "Tesing tqdm"):
    time.sleep(.5)

This is not a very important issue as I can always keep one instance of Emacs open for debugging and one for development and switch between the two instead of switching tabs when the debugger is running. But I thought it may be a good idea to inform you of the issue. FYI I am on commit #5356093.

Thanks again

svaante commented 7 months ago

Hi and thanks for the kind words, makes me happy that it's useful for somebody else :)

Nice bug report as well 👍

I will take a look at but until then you can use the new release on elpa or master which uses another default configuration for debugpy where the terminal output is in another buffer where this should be a non issue. But it would be nice if it worked in dape-repl will see what I can do.

haditim commented 7 months ago

Thanks for the reply. Using the new release (version 0.4.0 commit 68534d6), I get the following error with the default debugpy configuration. Am I doing something wrong?

* Welcome to Dape REPL! *
Available Dape commands: debug, next, continue, pause, step, out, restart, kill, disconnect, quit
Empty input will rerun last command.

* Command initialize timeout *
Initialize failed due to: timeout
* Command disconnect timeout *
Adapter connection shutdown without successfully initializing
Configuration:
  modes (python-mode python-ts-mode)
  ensure (lambda (config) (dape-ensure-command config) (let ((python (dape--config-eval-value (plist-get config 'command)))) (unless (zerop (call-process-shell-command (format "%s -c \"import debugpy.adapter\"" python))) (user-error "%s module debugpy is not installed" python))))
  fn (dape-config-autoport dape-config-tramp)
  command "python"
  command-args ("-m" "debugpy.adapter" "--host" "0.0.0.0" "--port" "43867")
  port 43867
  :request "launch"
  :type "executable"
  :cwd "/home/Python/tqdm/"
  :program "tqdm_debugging_test.py"
  :justMyCode nil
  :console "integratedTerminal"
  :showReturnValue t
  :stopAtEntry t
  command-cwd "/home/Python/tqdm/"
Exception in thread Client[1] message parser:
Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/debugpy/common/messaging.py", line 384, in __call__
    value = validate(value)
            ^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/debugpy/common/json.py", line 169, in validate
    raise ValueError("must be one of: {0!r}".format(list(values)))
ValueError: must be one of: ['event', 'request', 'response']

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.11/threading.py", line 1045, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.11/threading.py", line 982, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3.11/site-packages/debugpy/common/messaging.py", line 1295, in _parse_incoming_messages
    self._parse_incoming_message()
  File "/usr/lib/python3.11/site-packages/debugpy/common/messaging.py", line 1366, in _parse_incoming_message
    msg_type = message_dict("type", json.enum("event", "request", "response"))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/debugpy/common/messaging.py", line 390, in __call__
    raise message.isnt_valid("{0}{1}", json.repr(key), err)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/debugpy/common/messaging.py", line 521, in isnt_valid
    return self.error(InvalidMessageError, *args, **kwargs)
           ^^^^^^^^^^
AttributeError: 'str' object has no attribute 'error'
haditim commented 7 months ago

Upon further investigation, it seems that everything is fine up to commit 81b77eb and the commit 4ffaef2 has introduced the bug mentioned in my second message. Also the issue with escape characters does not exist as dape-shell buffer seems to handle them correctly.

svaante commented 7 months ago

Make sure to update jsonrpc from elpa as dape requires a version that is not included with emacs.

(use-package jsonrpc :ensure t)

You are installing dape from elpa of by straight this done this is a non issue as it's then done as part of the installation

haditim commented 7 months ago

Thanks for the reply. I do use straight and jsonrpc is already installed. I just added :ensure t and ran (require 'jsonrpc) before dape with the same error. I don't think this is an issue withjsonrpc not being installed.

svaante commented 7 months ago

What is your version of jsonrpc? It needs to be => 1.0.21. You can use describe-package to to find version number and package-upgrade to upgrade version.

haditim commented 7 months ago

Thanks a lot for the reply and sorry that I hadn't read the new readme. My jsonrpc package version was the built-in 1.0.16 and both issues are fixed after upgrading to 1.0.24. Closing this issue as both problems are solved.