From fd6469241bf5e49441684118ebccbb5c679dd833 Mon Sep 17 00:00:00 2001 From: Mitch Bradley Date: Sat, 12 Jun 2021 11:04:38 -1000 Subject: [PATCH] Better error messages for config file opening --- Grbl_Esp32/src/MachineConfig.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Grbl_Esp32/src/MachineConfig.cpp b/Grbl_Esp32/src/MachineConfig.cpp index d5bc47ef..242af0ad 100644 --- a/Grbl_Esp32/src/MachineConfig.cpp +++ b/Grbl_Esp32/src/MachineConfig.cpp @@ -480,12 +480,16 @@ size_t MachineConfig::readFile(const char* filename, char*& buffer) { if ((path.length() > 0) && (path[0] != '/')) { path = "/" + path; } - File file = SPIFFS.open(path, FILE_READ); - if (!file) { - log_info("Cannot open the config file " << path); + if (!SPIFFS.exists(path)) { + log_info("Missing config file " << path); return 0; } + File file = SPIFFS.open(path, FILE_READ); auto filesize = file.size(); + if (filesize == 0) { + log_info("config file " << path << " is empty"); + return 0; + } // log_debug("Configuration file has " << int(filesize) << " bytes"); buffer = new char[filesize + 1];