Fix error handling writing checkpoint