error handling in migration function