exit with proper error code on fail