Fixing error handling logic in parser