logErrorAndExit refactoring