Replace only if there are actually errors

Signed-off-by: Madhura Jayaratne <madhura.cj@gmail.com>