Add new test for error handling in save.

Fix some bugs found while writing these tests.