Skip to content

Commit 86121f1

Browse files
committed
Reinitialise secrets if empty, otherwise leave as-is
1 parent 293c8ba commit 86121f1

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/provisioning/tinyusb/Wippersnapper_FS.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,22 @@ void Wippersnapper_FS::parseSecrets() {
418418
// Attempt to deserialize the file's JSON document
419419
JsonDocument doc;
420420
DeserializationError error = deserializeJson(doc, secretsFile);
421-
if (error) {
421+
if (error == DeserializationError::EmptyInput)
422+
{
423+
if (WS.brownOutCausedReset)
424+
{
425+
fsHalt("ERROR: Empty secrets.json file, can't recreate due to brownout - recharge or must be fixed manually.");
426+
}
427+
else
428+
{
429+
// TODO: Can't serial print here, in next PR check we're not out of space
430+
WS_DEBUG_PRINTLN("ERROR: Empty secrets.json file, recreating...");
431+
secretsFile.close();
432+
createSecretsFile(); // calls fsHalt
433+
}
434+
}
435+
else if (error)
436+
{
422437
fsHalt(String("ERROR: Unable to parse secrets.json file - "
423438
"deserializeJson() failed with code") +
424439
error.c_str());

0 commit comments

Comments
 (0)