Tidy up syntax error handling so that tested error messages are preserved.