call done() correctly when error