remove trailing whitespaces
provide meaningful error message