meejah / txtorcon

Twisted-based asynchronous Tor control protocol implementation. Includes unit-tests, examples, state-tracking code and configuration abstraction.
http://fjblvrw2jrxnhtg67qpbzi45r7ofojaoo3orzykesly2j3c2m3htapid.onion/
MIT License
250 stars 72 forks source link

Easily check which `SocksError` was raised #214

Closed felipedau closed 7 years ago

felipedau commented 7 years ago

In a previous version of txtorcon, some errors raised came from txsocksx.error and I was able to check them with:

if failure.check(txsocksx.errors.HostUnreachable,
                 txsocksx.errors.TTLExpired):

As txsocksx was replaced by txtorcon's own implementation, now the errors are just SocksErrors and it looks like only their message can be checked ('TTL Expired', 'Host unreachable', etc). Is there a nice way to do that which I am not aware of?

Maybe if an errno attribute was added to the SocksError class or, preferably, if each error was an instance of its own class. That way it would be easy to:

if failure.check(txtorcon.socks.HostUnreachableError,
                 txtorcon.socks.TtlExpiredError):

What do think? Would that be useful? If so, let me know which of the options is preferred. I can send a PR with the changes.

Thanks!

meejah commented 7 years ago

Yes, I think that sounds like a good enhancement, especially if your application may respond differently to different errors.

A separate class for each SOCKS error is fine, I think there's only 6 of them. They should all have SocksError as a base, though, in case you don't care which error.