More tests for error cases in compile

Also some refactoring of the error structure. More cleanup work around
human-readable and CLI errors is still required.