jquast / blessed

Blessed is an easy, practical library for making python terminal apps

Home Page:http://pypi.python.org/pypi/blessed

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Capture initialization errors in Terminal.errors

avylove opened this issue · comments

An effort is made to fail gracefully and essentially disable styling when a Terminal instance can not be configured. While this creates a better user experience, it can make troubleshooting somewhat difficult for developers and more difficult for us when we are assisting developers.

To make troubleshooting easier, particularly in environments that are hard to recreate, we should capture errors as they are encountered during initialization of the Terminal class in a new instance variable Terminal.errors.

For example, we currently have this code:

try:
    stream_fd = (stream.fileno() if hasattr(stream, 'fileno') and
                 callable(stream.fileno) else None)
except (io.UnsupportedOperation, ValueError):
    stream_fd = None

It would be replaced with something like this:

stream_fd = None
if not hasattr(stream, 'fileno'):
    self.errors.append('stream has no fileno method')
elif not callable(stream.fileno):
    self.errors.append('stream.fileno is not callable')
else:
    try:
        stream_fd = stream.fileno()
    except (io.UnsupportedOperation, ValueError) as e:
        self.errors.append('Unable to determine stream file descriptor: %s' % e)

sounds fine,

just be sure to use warnings module

My thought is some conditions may not justify warnings, but we'd want to preserve them for troubleshooting. Essentially when someone says, "It isn't working", we can ask for the value of Terminal.errors and be able to piece together what happened during initialization.

Take a look at my approach, let me know what you think, or change things as needed.