ESP8266 repeatedly throws Exception(0)

I am making an IoT weighing scale with a load cell connected to an Arduino. The Arduino then sends data to an ESP8266 connected by serial which would subsequently update my database on Google's Firebase. However, my ESP8266 throws an exception when it starts. Half of the time it works perfectly fine. The other half, the following is thrown when I connect my cable to it. This error is repeatedly thrown so I think it might be an error inside void loop() but I can't seem to figure out what exactly is the problem. Also, my cables are not the best quality but I am not sure if that affects anything.

Note that the error message was cut short.

Exception (0):
epc1=0x4025803e epc2=0x00000000 epc3=0x00000000 excvaddr=0x0000000a depc=0x00000000

>>>stack>>>

ctx: sys
sp: 3fffe0c0 end: 3fffffb0 offset: 01a0
3fffe260:  00000000 00000000 00000000 00000000  
3fffe270:  00000000 00000000 00000000 40104b72  
3fffe280:  40104b54 3fffc100 0000001a 00000000  
3fffe290:  00000000 4025803e 00000000 00000000  
3fffe2a0:  400005e1 00000000 00000000 00000000  
3fffe2b0:  4025803e 00000033 00000010 00000000  
3fffe2c0:  4025803e 40266fd0 00000000 00000001  
3fffe2d0:  fbf8ffff 04000002 3feffe00 00000100  
3fffe2e0:  0000001a 00000018 04000102 40104b54

The following is my code on the ESP8266. I apologize for any bad programming habits. I am a beginner. Feel free to improve my code as well.

#include <ESP8266WiFi.h>
#include <FirebaseESP8266.h>

//Hidden for security
#define WIFINAME   
#define WIFIPASSWORD
#define BAUTRATE 9600
#define FIREBASE_HOST  
#define FIREBASE_COMMAND_ADDRESS
#define FIREBASE_AUTH 

WiFiClientSecure client;
FirebaseData firebaseData;
unsigned long previousTime;
String firebaseWriteAddress;
String firebaseReadAddress;
String weight; // Stored in a string to accomodate the "loading" text
bool maxWRead;
bool minWRead;
bool displayPrefRead;
bool instructedToConnectWifi;

void readWeights(){
  // function to read the min and max weights, then send to Arduino

  if (!maxWRead){
    String maxWAddress = firebaseReadAddress + "/Product/MaxW";
    if (Firebase.get(firebaseData,maxWAddress)){
      if (firebaseData.dataType() == "string"){
        String maxWMessage = "max:"+ firebaseData.stringData();
        Serial.println(maxWMessage);
        maxWRead = true;
      }
    }
  }

  if (!minWRead){
    String minWAddress = firebaseReadAddress + "/Product/MinW";
    if (Firebase.get(firebaseData,minWAddress)){
      if (firebaseData.dataType() == "string"){
        String minWMessage = "min:"+ firebaseData.stringData();
        Serial.println(minWMessage);
        minWRead = true;
      }
    }
  }
}

void readDisplayPref(){
  String displayAddress = firebaseReadAddress + "/Display";
  if (Firebase.get(firebaseData,displayAddress)){
    if (firebaseData.dataType() == "string"){
      String displayMessage = "dsp:"+ firebaseData.stringData();
      Serial.println(displayMessage);
      displayPrefRead = true;
    }
  }
}

void sendFireBase(){
  // function to send data to Firebase Real-time Database
  Firebase.setString(firebaseData, firebaseWriteAddress,weight);
}

void readFireBase(){
  Firebase.begin(FIREBASE_HOST,FIREBASE_AUTH);
  if(Firebase.get(firebaseData, FIREBASE_COMMAND_ADDRESS)){
    if (firebaseData.dataType() == "string"){
      String data = firebaseData.stringData();
      String command = data.substring(0,4);
      if (command == "read"){ 
        firebaseReadAddress = "/UserData/" + data.substring(4);
        readWeights();
        firebaseWriteAddress =  "/UserData/" + data.substring(4)
        + "/Weight";
      }
    }
  }
}

void connectWifi(){

  WiFi.begin(WIFINAME, WIFIPASSWORD);

  byte wifiCounter = 0;
  // Allow some buffer time to connect to WiFi
  while (WiFi.status() != WL_CONNECTED) {
    delay(100);
    wifiCounter ++;

    if (wifiCounter > 50){
      // tries for 5 sec.
      break;
    }
  }

  if (WiFi.status() == WL_CONNECTED){
    Serial.print("WiFi Connected!\n");
    instructedToConnectWifi = true;
  }

  else {
    Serial.print("Can't Connect. Trying Again\n");
    connectWifi();
  }
}

void readArd(){
// function to read Serial inputs from arduino
  String message = Serial.readStringUntil('\n');
    if (message == "ConnectWifi"){
      connectWifi();
    }
    else{
      weight = message;
      // stores weight without the percentage sign. Only stores if its within 0-100
      sendFireBase();
    }
}

void setup() {
  Serial.begin(BAUTRATE);
  previousTime = millis();
  maxWRead = false;
  minWRead = false;
  displayPrefRead = false;
  instructedToConnectWifi = false;
}

void loop() {

  if (Serial.available()){
    readArd();
  }

  if (instructedToConnectWifi){
      // if wifi disconnects halfway, auto connect back
      if (WiFi.status() != WL_CONNECTED){
      connectWifi();
    }
  }

   unsigned long currentTime = millis();
  if (currentTime - previousTime >2000){
    // cycles every 2 sec to prevent spam
    // TODO: fix overflow problem (49 days) if it becomes product

    if (instructedToConnectWifi){
      if (!minWRead || !maxWRead){
        // stop once max and min has been read
        readFireBase();
        previousTime = currentTime;
      }
      else {
        readDisplayPref();
        previousTime = currentTime;
      }
    }
  }
}

presumably that dump can identify the line of code causing the fault. but it could be in a library because of a bad, non-validated parameter.

the alternative is to narrow down which code is causing the exception.

one approach is to simply eliminate portions of code until the problem goes away and then narrow it down to as small a block of code as possible.

an #if 0/#endif can be used to "comment" out code. you might start with "iffing" out the bodies of functions. Changing from "#if 0" to #if 1" uncomments the code. #if/#else/#endif can be nested

void readFireBase(){
#if 0
    Firebase.begin(FIREBASE_HOST,FIREBASE_AUTH);
    if(Firebase.get(firebaseData, FIREBASE_COMMAND_ADDRESS)){
        if (firebaseData.dataType() == "string"){
            String data = firebaseData.stringData();
            String command = data.substring(0,4);
            if (command == "read"){
# if 1
                firebaseReadAddress = "/UserData/" + data.substring(4);
                readWeights();
                firebaseWriteAddress =  "/UserData/" + data.substring(4)
                + "/Weight";
# endif
            }
        }
    }
#endif
}

Start by decoding the stack trace:

Pieter