Check for invalid package names early in the codepath.

We already don't work with packages that contain '.' in the name, this just moves the error up and makes it clearer.