add guard against npe when creating the errors