console.log(variable_name); The value can be found printed on the console of the developer tools of the browser when you refresh the browser.
Now assume you are in the code written by someone else and you want to find out how exactly the function call is happening, so you can use
console.trace(variable_name); in that case, and the value with the whole stack trace of the function calls can be viewed in the browser console.
Whenever the program is being executed and debugger statement comes the execution is stopped, now you can play the execution, or can jump over/into the next function call, put the breakpoints in your code. And the most interesting part is that the value of the local variables can be seen just hovering the mouse over it.
Sometimes what happens that there isn’t any issue in the front end and the bug lies in the back end itself. Now for debugging the backend, you need to print the values in the server console. so you can simply write the
print (variable_name) in your Python code for that.
import pdb#use this statement where you want a breakpoint in your code.
Now whenever the set_traceback is reached the interpreter stops the execution and gives control to the debugger. Then you can navigate accordingly. But if you are using frappe you can use one shortcut to find out the function call stack. You can just simply use
frappe.throw("Anything here") This will print the full traceback in the bench console as Frappé automatically handles this exception.
For ex. if
frappe.throw("This will give the full traceback") statement is used in the item.py file, a traceback as given below can be found in the bench console.
Now maybe you are thinking how will I find whether the issue is because of front-end script or backend. so you can always cross check requests to find out whether you are sending the wrong request from the client side, or getting wrong data from the backend, or getting the right data but mishandled in the front end.
What if your logic is correct in both backend and frontend but somehow the data in the database isn’t getting stored properly. In this case, you can always access the database via
bench --site <sitename> mysql . This will give you access to MySQL console and you can run MySQL queries there. If you don’t feel comfortable in MySQL queries you can also access data via the
bench --site <sitename> console . This will open up Python console for you. You can get and manipulate data there via the frappe database API
Hope above given tricks and methods will help you to find out the problem more quickly and give you insights for any code. If you can’t still find out the solution you can always post your query on https://discuss.erpnext.com/
Please comment below if you know some cool trick for debugging.