Raise TypeError if the config file is malformed

Fixes #1504.