Throw exception on precondition failure.
Fixes #7967.
Fix bug for situation where no suitable index location is found.