Tracking Bugs¶

So far, we have assumed that failures would be discovered and fixed by a single programmer during development. But what if the user who discovers a bug is different from the developer who eventually fixes it? In this case, users have to report bugs, and one needs to ensure that reported bugs are systematically tracked. This is the job of dedicated bug tracking systems, which we will discuss (and demo) in this chapter.

Prerequisites

  • You should have read the Introduction to Debugging.
In [5]:
# ignore
if 'CI' in os.environ:
    # Can't run this in our continuous environment,
    # since it can't run a headless Web browser
    sys.exit(0)
In [6]:
# ignore
#
# WARNING: Unlike the other chapters in this book, 
# this chapter should NOT BE RUN AS A NOTEBOOK:
#
# * It will delete ALL data from an existing 
#   local _Redmine_ installation.
# * It will create new users and databases in an existing
#   local _MySQL_ installation.
# 
# The only reason to run this notebook is to create the book chapter,
# which is the task of Andreas Zeller (and possibly some translators).
# If you are not Andreas, you should exactly know what you are doing.

assert os.getenv('USER') == 'zeller'

Reporting Issues¶

So far, we have always assumed an environment in which software failures would be discovered by the very developers responsible for the code – that is, failures discovered (and fixed) during development. However, failures can also be discovered by third parties, such as

  • Testers whose job it is to test the code of developers
  • Other developers using the code
  • Users running the code as it is in production

In all these cases, developers need to be informed about the fact that the program failed; if they won't know that a bug exists, it will be hard to fix it. This means that we have to set up mechanisms for reporting bugs – manual ones and/or automated ones.

What Goes in a Bug Report?¶

Let us start with the information a developer requires to fix a bug. In a 2008 study \cite{Bettenburg2008}, Bettenburg et al. asked 872 developers from the Apache, Eclipse, and Mozilla projects to complete a survey on the most important information they need. From top to bottom, these were as follows:

Steps to Reproduce (83%)¶

This is a list of steps by which the failure would be reproduced. For instance:

  1. I started the program using $ python Debugger.py my_code.py.
  2. Then, at the (debugger) prompt, I entered run and pressed the ENTER key.

The easier it will be for the developer to reproduce the bug, the higher the chances it will be effectively fixed. Reducing the steps to those relevant to reproduce the bug can be helpful. But at the same time, the main problem experienced by developers as it comes to bug reports is incomplete information, and this especially applies to the steps to reproduce.

Stack Traces (57%)¶

These give hints on which parts of the code were active at the moment the failure occurred.

I got this stack trace:

Traceback (most recent call last):
  File "Debugger.py", line 2, in <module>
    handle_command("run")
  File "Debugger.py", line 3, in handle_command
    scope = s.index(" in ")
ValueError: substring not found (expected)

Even though stack traces are useful, they are seldom reported by regular users, as they are difficult to obtain (or to find if included in log files). Automated crash reports (see below), however, frequently include them.

Test Cases (51%)¶

Test cases that reproduce the bug are also seen as important:

I can reproduce the bug using the following code:

import Debugger

Debugger.handle_command("run")

Non-developers hardly ever report test cases.

Observed Behavior (33%)¶

What the bug reporter observed as a failure.

The program crashed with a ValueError.

In many cases, this mimics the stack trace or the steps to reproduce the bug.

Screenshots (26%)¶

Screenshots can further illustrate the failure.

Here is a screenshot of the Debugger failing in Jupyter.

Screenshots are helpful for certain bugs, such as GUI errors.

Expected Behavior (22%)¶

What the bug reporter expected instead.

I expected the program not to crash.

Configuration Information (< 12%)¶

Perhaps surprisingly, the information that was seen as least relevant for developers was:

  • Version (12%)
  • Build information (8%)
  • Product (5%)
  • Operating system (4%)
  • Component (3%)
  • Hardware (0%)

The relative low importance of these fields may be surprising as entering them is usually mandated in bug report forms. However, in \cite{Bettenburg2008}, developers stated that

[Operating System] fields are rarely needed as most [of] our bugs are usually found on all platforms.

This not meant to be read as these fields being totally irrelevant, as, of course, there can be bugs that occur only on specific platforms. Also, if a bug is reported for an older version, but is known to be fixed in a more current version, a simple resolution would be to ask the user to upgrade to the fixed version.

Reporting Crashes Automatically¶

If a program crashes, it can be a good idea to have it automatically report the failure to developers. A common practice is to have a crashing program show a bug report dialog allowing the user to report the crash to the vendor. The user is typically asked to provide additional details on how the failure came to be, and the crash report would be sent directly to the vendor's database:

The automatic report typically includes a stack trace and configuration information. These two do not reveal too many sensitive details about the user, yet already can help a lot in fixing a bug. In the interest of transparency, the user should be able to inspect all information sent to the vendor.

Besides stack traces and configuration information, such crash reporters could, of course, collect much more - say the data the program operated on, logs, recorded steps to reproduce, or automatically recorded screenshots. However, all of these will likely include sensitive information; and despite their potential usefulness, it is typically better to not collect them in the first place.

Effective Issue Reporting¶

When writing an issue report, it is important to look at it from the developer's perspective. Developers not only require information on how to reproduce the bug; they also want to work effectively and efficiently. The following aspects will all help developers with that:

  • Have a concise summary. A good summary should quickly and uniquely identify a bug. Make it easy to understand such that the reader can know if the bug has been reported and/or fixed.
  • Be clear and concise. Provide necessary information (as shown above) and avoid any extras. Use meaningful sentences and simple words. Structure the report into enumerations and bullet lists.
  • Do not assume context. Make no assumption that the developer knows all about your bug. Find out whether similar issues have been reported before and reference them.
  • Avoid commanding tones. Developers enjoy autonomy in their work, and coming across as too authoritative hurts morale.
  • Avoid sarcasm. Same as above. If you think you can get a volunteer to fix a bug in an open source program for you with sarcasm or commands – good luck with that.
  • Do not assume mistakes. Do not assume some developer (or anyone) has made a mistake. In many cases, issues can be resolved on your side.
  • One issue per report. If you have multiple issues, split them in multiple reports; this makes it easier to process them.

An Issue Tracker¶

At the developer's end, all issues reported need to be tracked – that is, they have to be registered, they have to be checked, and of course, they have to be addressed. This process takes place via dedicated database systems, so-called bug tracking systems.

The purposes of an issue tracking system include

  • to collect and store all issue reports;
  • to check the status of issues at all times; and
  • to organize the debugging and development process.

Let us illustrate how these steps work, using the popular Redmine issue tracking system.

This is what the Redmine tracker starts with:

In [53]:
# ignore
redmine_gui.get(redmine_url + '/login')
screenshot(redmine_gui)
Out[53]:
No description has been provided for this image

After we login, we see our account:

In [54]:
# ignore
redmine_gui.find_element(By.ID, "username").send_keys("admin")
redmine_gui.find_element(By.ID, "password").send_keys("admin001")
redmine_gui.find_element(By.NAME, "login").click()
screenshot(redmine_gui)
Out[54]:
No description has been provided for this image

We start with a list of projects.

In [59]:
# ignore
redmine_gui.get(redmine_url + '/projects')
screenshot(redmine_gui)
Out[59]:
No description has been provided for this image

Let us choose the (one) "debuggingbook" project.

In [60]:
# ignore
redmine_gui.get(redmine_url + '/projects/debuggingbook')
screenshot(redmine_gui)
Out[60]:
No description has been provided for this image

Reporting an Issue¶

The most basic task of a bug tracker is to report bugs. However, a bug tracker is a bit more general than just bugs – it can also track feature requests, support requests, and more. These are all summarized under the term "issue".

Let us take the role of a bug reporter – pardon, an issue reporter – and report an issue. We can do this right from the Redmine menu.

In [61]:
# ignore
redmine_gui.get(redmine_url + '/issues/new')
screenshot(redmine_gui)
Out[61]:
No description has been provided for this image

Let's give our bug a name:

In [62]:
issue_title = "Does not render correctly on Nokia Communicator"
In [63]:
issue_description = \
"""The Debugging Book does not render correctly on the Nokia Communicator 9000.

Steps to reproduce:
1. On the Nokia, go to "https://debuggingbook.org/"
2. From the menu on top, select the chapter "Tracking Origins".
3. Scroll down to a place where a graph is supposed to be shown.
4. Instead of the graph, only a blank space is displayed.

How to fix:
* The graphs seem to come as SVG elements, but the Nokia Communicator does not support SVG rendering. Render them as JPEGs instead.
"""
In [64]:
# ignore
redmine_gui.get(redmine_url + '/issues/new')

redmine_gui.find_element(By.ID, 'issue_subject').send_keys(issue_title)
redmine_gui.find_element(By.ID, 'issue_description').send_keys(issue_description)
screenshot(redmine_gui)
Out[64]:
No description has been provided for this image
In [65]:
# ignore
redmine_gui.find_element(By.ID, 'issue_assigned_to_id').click()
screenshot(redmine_gui)
Out[65]:
No description has been provided for this image
In [66]:
# ignore
redmine_gui.execute_script("window.scrollTo(0, document.body.scrollHeight);")
screenshot(redmine_gui)
Out[66]:
No description has been provided for this image

Clicking on "Create" creates the new issue report.

In [67]:
# ignore
redmine_gui.find_element(By.NAME, 'commit').click()
screenshot(redmine_gui)
Out[67]:
No description has been provided for this image

Our bug has been assigned an issue number (#1 in that case). This issue number (also known as bug number, or problem report number) will be used to identify the specific issue from this point on in all communication between developers. Developers will know which issues they are working on; and in any change to the software, they will refer to the issue the change relates to.

Over time, issue databases can grow massively, especially for popular products with several users. As an example, consider the Mozilla Bugzilla issue tracker, collecting issue reports for the Firefox browser and other Mozilla products.

In [68]:
# ignore
from bookutils import quiz
In [69]:
quiz("How many issues have been reported over time in Mozilla Bugzilla?",
    [
        "More than ten thousand",
        "More than a hundred thousand",
        "More than a million",
        "More than ten million"
    ], '370370367 // 123456789')
Out[69]:

Quiz

How many issues have been reported over time in Mozilla Bugzilla?





Yes, it is that many! Look at the bug IDs in this recent screenshot from the Mozilla Bugzilla database:

In [70]:
# ignore
redmine_gui.get("https://bugzilla.mozilla.org/buglist.cgi?quicksearch=firefox")
In [71]:
# ignore
screenshot(redmine_gui)
Out[71]:
No description has been provided for this image

Let us enter a few more reports into our issue tracker.

Managing Issues¶

Let us now switch sides and take the view of a developer whose job it is to actually handle all these issues. When our developers log in, the first thing they see is that there are a number of new issues that are all "open" – that is, in need to be addressed. (For a typical developer, this may well be the first task of the day.)

In [78]:
# ignore
redmine_gui.get(redmine_url + "/projects/debuggingbook")
screenshot(redmine_gui)
Out[78]:
No description has been provided for this image

Clicking on "View all issues" shows us all issues reported so far.

In [79]:
# ignore
redmine_gui.get(redmine_url + '/projects/debuggingbook/issues')
redmine_gui.execute_script("window.scrollTo(0, document.body.scrollHeight);")
screenshot(redmine_gui)
Out[79]:
No description has been provided for this image

Let us do some bug triaging here. Bug report #2 is not a bug – it is a feature request. We invoke its "actions" pop-up menu and mark it as "Feature".

In [80]:
# ignore
redmine_gui.get(redmine_url + "/issues/")
In [81]:
# ignore
redmine_gui.find_element(By.XPATH, "//tr[@id='issue-2']//a[@title='Actions']").click()
time.sleep(0.25)
In [82]:
# ignore
tracker_item = redmine_gui.find_element(By.XPATH,
    "//div[@id='context-menu']//a[text()='Tracker']")
actions = webdriver.ActionChains(redmine_gui)
actions.move_to_element(tracker_item)
actions.perform()
screenshot(redmine_gui)
Out[82]:
No description has been provided for this image
In [83]:
# ignore
redmine_gui.find_element(By.XPATH, "//div[@id='context-menu']//a[text()='Feature']").click()

The same applies to bugs #3 and #4 (missing PDF) and #6 (no support for C++). We mark them as such as well.

In [84]:
# ignore
def mark_tracker(issue: int, tracker: str) -> None:
    redmine_gui.get(redmine_url + "/issues/")
    redmine_gui.find_element(By.XPATH, 
        f"//tr[@id='issue-{str(issue)}']//a[@title='Actions']").click()
    time.sleep(0.25)

    tracker_item = redmine_gui.find_element(By.XPATH,
        "//div[@id='context-menu']//a[text()='Tracker']")
    actions = webdriver.ActionChains(redmine_gui)
    actions.move_to_element(tracker_item)
    actions.perform()
    time.sleep(0.25)

    redmine_gui.find_element(By.XPATH,
        f"//div[@id='context-menu']//a[text()='{tracker}']").click()
In [85]:
# ignore
mark_tracker(3, "Feature")
mark_tracker(4, "Feature")
mark_tracker(6, "Feature")
In [86]:
# ignore
redmine_gui.get(redmine_url + "/issues/")
redmine_gui.execute_script("window.scrollTo(0, document.body.scrollHeight);")
screenshot(redmine_gui)
Out[86]:
No description has been provided for this image

The fact that we marked these issues as "feature requests" does not mean that they will not be worked on – on the contrary, a feature requested by management can have an even higher priority than a bug. Right now, though, we will give our first priority to the bugs listed.

Assigning Priorities¶

After we have decided the priority for individual bugs, we can make this decision explicit by assigning a priority to each bug. This allows our co-developers to see which things are the most pressing to work on.

Let us assume we have an important customer for whom fixing issue #1 is important. Through the context menu, we can assign issue #1 a priority of "Urgent".

In [87]:
# ignore
redmine_gui.get(redmine_url + "/issues/")
In [88]:
# ignore
redmine_gui.find_element(By.XPATH, "//tr[@id='issue-1']//a[@title='Actions']").click()
time.sleep(0.25)
In [89]:
# ignore
priority_item = redmine_gui.find_element(By.XPATH, "//div[@id='context-menu']//a[text()='Priority']")
actions = webdriver.ActionChains(redmine_gui)
actions.move_to_element(priority_item)
actions.perform()
screenshot(redmine_gui)
Out[89]:
No description has been provided for this image
In [90]:
# ignore
redmine_gui.find_element(By.XPATH, "//div[@id='context-menu']//a[text()='Urgent']").click()

We see that issue #1 is now listed as urgent.

In [91]:
# ignore
redmine_gui.get(redmine_url + "/issues/")
redmine_gui.execute_script("window.scrollTo(0, document.body.scrollHeight);")
screenshot(redmine_gui)
Out[91]: