Reading Python Exception messages

When it comes to errors and exceptions, it is easy to panic and feel like the error message is providing no helpful information at all. When this happens I find it useful to slow down and read the message very slowly. Error messages are unlikely to contain extra words, they are direct and to the point. Each word is significant and has a purpose in being present.

Let's take an example message and break it down to understand what the message is communicating.

django.urls.exceptions.NoReverseMatch: Reverse for 'home' not found. 'home' is not a valid view function or pattern name.

Part 1: django.urls.exceptions.NoReverseMatch
Part 2: Reverse for 'home' not found.
Part 3: 'home' is not a valid view function or pattern name.

The first part of the message is the type of excption being raised. This provides a clue as to what is wrong, here NoReverseMatch shows it's something to do with reversing and urls.

The next sentence clearly tells what is wrong, Django hasn't found a url named 'home'. Finally this last sentence further explains the problem or might provide a potential solution. In the above example, Django is telling us that it is specifically looking for a view function name or url pattern name and cannot find one named 'home'.

From this error message we have the following initial debug steps:

  1. Check for views or urls named 'home' or similar of such names.
  2. Search for the 'home' string across the codebase to see what comes up.
  3. Review recent changes to view and urls.