Better error message on excaption in smart_dispatch.py

Also fixed another bug in test.