Structured error reporting.

And minor fixes. And better tests for warnings and errors.