Compiler code refactoring for a clean separation between first stage and second stage error handling