trepca's notes

Bad Error Messages

I’m surprised programmers don’t talk more about error messages. We encounter them every day, yet you rarely see any constructive discussion about them, maybe

error: no error

Let’s take Python for example:

IndexError and ValueError

index = 10
empty_list = [1,2,3,4,5,6,7,8,9]
for x in range(1000):
     empty_list[index + x]

Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
IndexError: list index out of range

empty_list.index('hehe')

Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
ValueError: list.index(x): x not in list

Printing out which index was out of range would definitely save me a minute or more, not to mention how annoying this is for newbies.

ValueError: 10 not in list [1,2,3,4 ...]

Paranthesis of hell

>>> if 1:
    ...     test = ((1,2, 3)
    ...     test2 = None
File "<stdin>", line 3
    test2 = None
         ^
SyntaxError: invalid syntax

Python forums are full of these questions. Would it be so hard to add (“Maybe you’re missing an end parathesis?”)

In general, I try to suggest solutions and provide some context to the error, that way it’s much easier for other people to debug.

blog comments powered by Disqus