Raise TypeError if the config file is malformed

Fixes #1504.
I agree. And include the file name in the message for maximum clarity. This is a message for people who have done something very strange. :smile: So it's important to be as helpful as possible.