Better Error Logging with Frappe

Bad Error Handling is one of the toughest problems in software architecture and a reason for most breakdowns

 · 2 min read

Software code is usually designed to run in a certain way, with certain inputs. If the code does not receive correct input (or any input!) then it fails. For example a wrong Customer ID will cause your Invoice to fail.

Most software is designed to handle such cases, but this is not as easy as it sounds. For example detecting a bad email id is a hard problem.

When we build applications with a user interface, these bad inputs are easy to identify and protect the user against. Also the result of a bad error is immediately visible to the user or tester who reports it back to the developer.

But when we design systems that talk to other systems, these errors often go un-noticed and happen at odd times, when there is no user to observe or report it. Hence when dealing with integrations, error handling becomes very critical.

In Frappe, so far we had a mixed system for Error Handling. There was the Scheduler Log* that got updated when something failed, and Max Morias' *Error Snapshot that detected errors at a much deeper level. For a developer to explicitly log errors, there was no simple mechanism.

Error Log

So we are now introducing the Error Log which is a renamed Scheduler Log. This is the default place for a software to report when something fails.

To call it, from code you can just write: frappe.log_error(frappe.get_traceback(), 'payment failed')

This will immediately log it into the Error Log table (which is MyISAM type, so you need not commit) and can be viewed by the user or administrator.

Error Log

Bad Error Handling is one of the biggest reasons for software to fail and as ERPNext keeps building more integrations, it is important to improve the error handling code!

Rushabh Mehta

Rushabh is a software developer and founder of ERPNext. He usually writes about the startup experience, open source and the technologies he is working on.

Add a comment
Ctrl+Enter to add comment

Victor 6 months ago

Hi Suad. In the global search on top of ERPNext screen, you can type "Error Log List" to get to the error log page shown in this article. Hope it helps!

Suad 1 year ago

I just can not understand why in such a details article we can not see how to get to this menu point. I can't see any form, menu point in my frappe - erpnext site. So how should we get to the screen you are showing. Please think next time that there are plenty people trying to learn ERPNext and this is not as easy to read your article.

Thank you Suad