Raise appropriate error if object does not have attribute