Return proper exit code on error