wmcbrine

Joined: 04 Jan 2008 Posts: 444
|
Posted: Fri Feb 22, 2008 7:22 pm Post subject: Tip: Python error messages are usually readable |
|
|
I see some requests for help from people who include the Python "traceback", with the error explained right in it. I suspect some are overlooking it, partly because the most relevant part is at the end -- the rest of the lines just let you follow the path of execution through the program -- and partly because people are so used to cryptic error messages that they just assume they won't be able to read it. But take a look at this example:
| Code: | Traceback (most recent call last):
File "/usr/local/tivo/pyTivo/pyTivo.py", line 11, in <module>
httpd.add_container(section, settings)
File "/usr/local/tivo/pyTivo/httpserver.py", line 22, in add_container
settings['content_type'] = GetPlugin(settings['type']).CONTENT_TYPE
File "/usr/local/tivo/pyTivo/plugin.py", line 13, in GetPlugin
module = __import__(module_name, globals(), locals(), name)
File "/usr/local/tivo/pyTivo/plugins/photo/photo.py", line 28, in <module>
import Image
ImportError: No module named Image
|
I'm picking on this one because KRKeegan just did a patch to replace it with "Photo Plugin Error: The Python Imaging Library is not installed" and suppress the traceback. I don't really disagree with that, but I think this is the sort of error message that the average user should be able to tackle as it is. Let's take a look at that last line:
| Code: | ImportError: No module named Image
|
That's the whole error, really, and it's in fairly plain English. It says that it tried to load a module named "Image", and couldn't find it. Well, you might not know what a module is, or where the Image module comes from, but it probably won't take you long to find out. What does the rest of the traceback tell us? Moving upwards from the bottom:
| Code: | File "/usr/local/tivo/pyTivo/plugins/photo/photo.py", line 28, in <module>
import Image
|
Here's the exact line of the exact file that caused the problem. "import Image" doesn't further illuminate anything, but we can see that it's the photo plugin (photo.py) that wants the Image module.
In this case, the rest of the traceback isn't really useful, but it might be in some circumstances. You can see that it was the GetPlugin() function that tried to load photo.py, and in turn the add_container() function that called GetPlugin(). _________________ My pyTivo fork |
|