How to add debugger in frappe?

I want to add debugger so how to add that please help?

1 Like

Server side you can use:

frappe.throw("What went wrong")

or

frappe.log_error("Write this to error log")

And client side you can use:

window.alert("sometext");

or

console.log("got it");
5 Likes

Thank you so much

1 Like

Thereā€™s also frappe.msgprint('debug message') for gentler debug prints on the backend.

1 Like

is it for development or preoduction??

It works for production configuration with developer_mode enabled. I didnā€™t test it on the pure production server yet.

1 Like

ok thanks for the reply

it works there also

1 Like

There are instructions how to setup Visual Studio Code to debug: https://github.com/frappe/erpnext/wiki/VSCode-Debugging-for-Frappe-Python

That way you can debug controllers and whitelisted functions. This is not an option (or only a desperate one) for your productive environment.

I also just found out how to debug code started with ā€œbench execute ā€¦ā€.
This solution uses Visual Studio Code.
Your workspace must be ~/frappe-bench/apps.
Edit your launch.json and add this configuration:

`        {
        "name": "bench execute",
        "type": "python",
        "request": "launch",
        "program": "${workspaceFolder}/frappe/frappe/utils/bench_helper.py",
        "args": [
            "frappe",
            "execute",
            "yourapp.yourapp.doctype.yourdoctype.yourdoctype.your_function",
        ],
        "python": "${workspaceFolder}/../env/bin/python",
        "cwd": "${workspaceFolder}/../sites",
        "env": {
            "DEV_SERVER": "1"
        }
    },

`

This will launch method your_method() in ~/frappe-bench/apps/yourapp/yourapp/doctype/yourdoctype/yourdoctype.py

I found this by try and error. I have no idea what "ā€œenvā€: { ā€œDEV_SERVERā€: ā€œ1ā€ } means.

1 Like