Raise TypeError if the config file is malformed

Fixes #1504.
Seems to me we'll do better by raising a custom exception with a more meaningful message in this particular case.