Setup Debugger for ERPNext without Docker | Debugger For VS-Code

Assume that you had use this command to create the frappe setup

bench init --frappe-branch version-13 frappe-bench

step1: do ls and check the project was created with the name of frappe-bench if yes do this

cd frappe-bench

step2: in VS-Code create launch.json file inside .vscode directory

mkdir .vscode
cd .vscode
touch launch.json

This two command create the directory and create the launch.json file inside the .vscode directory

Add this in launch.json file

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
      {
        "name": "Bench Web",
        "type": "python",
        "request": "launch",
        "program": "${workspaceFolder}/apps/frappe/frappe/utils/bench_helper.py",
        "args": [
          "frappe",
          "serve",
          "--port",
          "8000",
          "--noreload",
          "--nothreading"
        ],
        "python": "${workspaceFolder}/env/bin/python",
        "cwd": "${workspaceFolder}/sites",
        "env": {
          "DEV_SERVER": "1"
        }
      },]
}

Select the Bench Web and hit the play icon
Note: make sure while running this command you shoud be at the frappe-bench directory

2 Likes

@Antony_Praveenkumar

There’s some additional setup that’s also required in order to avoid port conflicts when debugging. The extra steps are available in Frappe’s documentation.

yeah I’m also facing the conflict but i don’t know where to setup please help me to setup

Since the bench serve --port 8000 process in the Procfile is now being handled by VSCode’s launch.json, you will need to comment it out in the Procfile by adding the # character at the start of the line, like so:

# web: bench serve --port 8000

1 Like

I’m facing this issue while running the debugger

Redis cache server not running. Please contact Administrator / Tech support

Procfile

redis_cache: redis-server config/redis_cache.conf
redis_socketio: redis-server config/redis_socketio.conf
redis_queue: redis-server config/redis_queue.conf

# web: bench serve --port 8000

socketio: /usr/local/bin/node apps/frappe/socketio.js

watch: bench watch

schedule: bench schedule
worker_short: bench worker --queue short 1>> logs/worker.log 2>> logs/worker.error.log
worker_long: bench worker --queue long 1>> logs/worker.log 2>> logs/worker.error.log
worker_default: bench worker --queue default 1>> logs/worker.log 2>> logs/worker.error.log

Error I’m facing is

127.0.0.1 - - [17/Jan/2023 12:05:48] "GET /api/method/frappe.desk.form.load.getdoctype?doctype=Salary+Slip&with_parent=1&cached_timestamp=&_=1673937341641 HTTP/1.1" 200 -
Traceback (most recent call last):
  File "env/lib/python3.10/site-packages/redis/connection.py", line 559, in connect
    sock = self._connect()
  File "env/lib/python3.10/site-packages/redis/connection.py", line 615, in _connect
    raise err
  File "env/lib/python3.10/site-packages/redis/connection.py", line 603, in _connect
    sock.connect(socket_address)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "apps/frappe/frappe/app.py", line 69, in application
    response = frappe.api.handle()
  File "apps/frappe/frappe/api.py", line 55, in handle
    return frappe.handler.handle()
  File "apps/frappe/frappe/handler.py", line 38, in handle
    data = execute_cmd(cmd)
  File "apps/frappe/frappe/handler.py", line 76, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "apps/frappe/frappe/__init__.py", line 1457, in call
    return fn(*args, **newargs)
  File "apps/frappe/frappe/desk/doctype/route_history/route_history.py", line 66, in deferred_insert
    _deferred_insert("Route History", json.dumps(routes))
  File "apps/frappe/frappe/deferred_insert.py", line 10, in deferred_insert
    frappe.cache().rpush(queue_prefix + doctype, records)
  File "apps/frappe/frappe/utils/redis_wrapper.py", line 140, in rpush
    super(RedisWrapper, self).rpush(self.make_key(key), value)
  File "env/lib/python3.10/site-packages/redis/client.py", line 2016, in rpush
    return self.execute_command('RPUSH', name, *values)
  File "env/lib/python3.10/site-packages/redis/client.py", line 898, in execute_command
    conn = self.connection or pool.get_connection(command_name, **options)
  File "env/lib/python3.10/site-packages/redis/connection.py", line 1192, in get_connection
    connection.connect()
  File "env/lib/python3.10/site-packages/redis/connection.py", line 563, in connect
    raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 111 connecting to localhost:13000. Connection refused.

redis.exceptions.ConnectionError: Error 111 connecting to localhost:13000. Connection refused.

Note:

This error not only happening after the change, it’s happening before also

The Procfile is just a list of processes that need to run to bootstrap the Frappe server, and the way Frappe uses it is via bench start.

When you created the debugger configuration in VSCode, you’re attaching only the web process to it, which is why you had to remove it from the Procfile.

But the remaining processes in Procfile still need to run (like redis, background, etc.) and so you still need to run bench start (with the modified Procfile) in a separate terminal instance.

2 Likes

Thank You @RohanB

:white_check_mark: Solution :white_check_mark:

Step1: Create a .vscode/launch.json file in workspace directory

Step2: Add this code in launch.json file

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Bench",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/apps/frappe/frappe/utils/bench_helper.py",
            "args": [
                "frappe", "serve", "--port", "8002", "--noreload", "--nothreading"
            ],
            "cwd": "${workspaceFolder}/sites",
            "env": {
                "DEV_SERVER": "1"
            }
        }
    ]
}

Step3 Comment this line web: bench serve --port 8000 from Prockfile like this


redis_cache: redis-server config/redis_cache.conf
redis_socketio: redis-server config/redis_socketio.conf
redis_queue: redis-server config/redis_queue.conf

# web: bench serve --port 8000

socketio: /usr/local/bin/node apps/frappe/socketio.js

watch: bench watch

schedule: bench schedule
worker_short: bench worker --queue short 1>> logs/worker.log 2>> logs/worker.error.log
worker_long: bench worker --queue long 1>> logs/worker.log 2>> logs/worker.error.log
worker_default: bench worker --queue default 1>> logs/worker.log 2>> logs/worker.error.log

Step5: Run this command in different terminal

bench start

Step6: Run debugger in workspaceFolder F5 (shorcut key)

Now you can start debugging

3 Likes

Step6: Run debugger in workspaceFolder Ctrl+F5 (shorcut key)

Just a note: In VSCode, the Ctrl + F5 shortcut will run the web process without enabling the debugger. You want to do a simple F5 or Run -> Start Debugging from the toolbar to actually enable the debugger.

2 Likes

If we get this working it’ll be nice debugging experience.

break points on js and python will take us through well integrated flow.

2 Likes

I was searching the forum for “pythonPath” complain from VS Code Debug launcher and I came across this thread.

I see in your launch.json you have removed the “python” path property, so you’re not using the python version of Frappe. Is that ok?

What if versions differ from system version?
Also, does the server using this launch.json use system version to run the site’s server operations?