Better handle errors when saving files