Add nil check before dereference of `error`.

I have a crash because of the missing check in some code I maintain, but I have been unable to distill a proper test case from it. Still, I think it is clear that `error` should be checked before dereferencing it.