throw better error message if setting value is of invalid type