heynemann / pyvows

Python implementation of Vows.js
http://pyvows.org
MIT License
133 stars 28 forks source link

Handling generative topics like simple topics if they produce an exception #89

Closed Telofy closed 11 years ago

Telofy commented 11 years ago

If an exception occurs in a topic, the value remains iterable since exceptions, somehow, are iterable. The result is that the entries (i.e. the error message string) are handed down to the vows where they cause strange errors that are hard to debug.

By resetting is_generator to False, these errors are handed to the vows unchanged, so that they can actually see the error type and topic.error.

Since most of my topics are not supposed to produce exceptions, it would be nice to have something like Vows.NotErrorContext that instead of just adding a vow, does not execute any vows in case of an error in the topic, and also prints a complete traceback of the error. The API might be a function decorator for topic() that sets a function attribute heeded by the runner.

Telofy commented 11 years ago

This is my current workaround for showing the error.

class NoErrorContext(Vows.Context):

    def runs_at_all(self, topic):
        if hasattr(topic, 'error'):
            exc_type, exc_value, exc_traceback = topic.error
            raise exc_type, exc_value, exc_traceback