fix warning and improve error message

(thanks to R.P.)