Properly check the return value before try to use error.