Fix risk of nullpointer when handling errors 1/2