Add FAIL_ON_DUPLICATES flag to control clean exit