The error indicates your operating system and the IDE lost contact with the Arduino. You should supply power to the motors separate from supplying power to the Arduino. My guess is that you were trying to supply the motors with power from the Arduino, and caused the Arduino to reboot. Post a drawing of your project to identify the items, a picture of the wiring and the sketch you are using.