Fix TypeError catching in migration