Make showing caret in error reporting more robust