Prune the cd history only if there was no error.