Use a more accurate error message, fixes #3282