Skip to content

Commit

Permalink
Reinitialise secrets if empty, otherwise leave as-is
Browse files Browse the repository at this point in the history
  • Loading branch information
tyeth committed Nov 8, 2024
1 parent 293c8ba commit 3fc98a2
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/provisioning/tinyusb/Wippersnapper_FS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,23 @@ 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();
wipperFatFs.remove("/secrets.json");
createSecretsFile(); // calls fsHalt
}
}
else if (error)
{
fsHalt(String("ERROR: Unable to parse secrets.json file - "
"deserializeJson() failed with code") +
error.c_str());
Expand Down

0 comments on commit 3fc98a2

Please sign in to comment.