Fix error cases to not dereference nil error.