I've recently bought my Uno WiFi Rev 2 board and I encountered a mystical error, which as I looked up the internet happened to many others too, yet no solution was provided anywhere.
This thread sums it up nicely, I had the same problem: Error uploading sketches
It's the unexpected error thing.
For me the solution was in realising my own ignorance: You don't need a separate power supply for the board if it is connected to the computer via USB... When I first unboxed the board I automatically hooked it up with an external power supply, to see if it is working properly. (leds lighting etc.) Then I connected the USB cable, and started by uploading an example sketch, which did not work, although all the settings were correct. After 2 days of online searching I happened to transport the board to another computer, where I've forgot to connect the external power, and all the once It worked flawlessly. So all in all if the board is connected to the computer via USB, don't connect an external power supply at the same time, because you will then encounter the error described in the thread mentioned.