Add useful error messages and tests.