"An error occurred during uploading."

I am trying to get my ESP8266's MAC or IP addresses.

These are my two possible codes:

//////////////////// S E R V E R /////////////////

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

/* configuration  wifi */
const char *ssid = "SKY19DA";

ESP8266WebServer server(80);

void handleRoot() { 
  server.send(200, "text/html", "<h1>You are connected</h1>");
  String addy = server.client().remoteIP().toString();
  Serial.println(addy);
}

void setup() {
  delay(1000);
  Serial.begin(115200);
  Serial.println();
  Serial.print("Configuring access point...");
  WiFi.softAP(ssid);
  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
  server.on("/", handleRoot);
  server.begin();
  Serial.println("HTTP server started");  
}
 
void loop() {
  server.handleClient();    
}
#include <ESP8266WiFi.h>
 
void setup(){
 
   Serial.begin(115200);
   delay(500);
 
   Serial.println();
   Serial.print("MAC: ");
   Serial.println(WiFi.macAddress());
 
}
 
void loop(){}

Firstly, which one is better?

Secondly (and this is the main reason I am writing) both the codes, when uploading, say "An error occurred during uploading." I get this error when trying to upload any sketch, not just this one.

Full error message:

Arduino: 1.8.4 (Mac OS X), Board: "Generic ESP8266 Module, 80 MHz, 40MHz, DIO, 115200, 512K (64K SPIFFS), ck, Disabled, None"
An error occurred during uploading.

My settings:

Board: Generic ESP8266 Module
Flash mode: DIO
Flash frequency: 40MHz
Flash size: 512K (64K SPIFFS)
Debug port: Disabled
Debug level: None
Reset method: ck
Upload speed: 115200
Port: dev/cu.wchusbserial620
Programmer: AVRISP mkll

Please help.