Fix 1761

This fixes reporting of unexpected errors in the compiler and removes our reliance on the non-standard method `.trimLeft`.