diff --git a/src/provisioning/tinyusb/Wippersnapper_FS.cpp b/src/provisioning/tinyusb/Wippersnapper_FS.cpp index f2405074..a12514b5 100644 --- a/src/provisioning/tinyusb/Wippersnapper_FS.cpp +++ b/src/provisioning/tinyusb/Wippersnapper_FS.cpp @@ -418,7 +418,22 @@ void Wippersnapper_FS::parseSecrets() { // Attempt to deserialize the file's JSON document JsonDocument doc; DeserializationError error = deserializeJson(doc, secretsFile); - if (error) { + if (error == DeserializationError::EmptyInput) + { + if (WS.brownOutCausedReset) + { + fsHalt("ERROR: Empty secrets.json file, can't recreate due to brownout - recharge or must be fixed manually."); + } + else + { + // TODO: Can't serial print here, in next PR check we're not out of space + WS_DEBUG_PRINTLN("ERROR: Empty secrets.json file, recreating..."); + secretsFile.close(); + createSecretsFile(); // calls fsHalt + } + } + else if (error) + { fsHalt(String("ERROR: Unable to parse secrets.json file - " "deserializeJson() failed with code") + error.c_str());