Better error message if the length of the shape cannot be determined.

Fixes gh-1337