Merge pull request #131 from tmatsuo/discovery-cache

Fixed a NameError on exception; added a unit test.