added try catch for more safety
All checks were successful
EIVE/eive-obsw/pipeline/pr-develop This commit looks good
EIVE/eive-obsw/pipeline/head This commit looks good

This commit is contained in:
Robin Müller 2022-03-03 19:13:43 +01:00
parent e07713a6f7
commit ebdd3914f4
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814

View File

@ -11,7 +11,12 @@ ReturnValue_t NVMParameterBase::readJsonFile() {
if (std::filesystem::exists(fullName)) {
// Read JSON file content into object
std::ifstream i(fullName);
i >> json;
try {
i >> json;
} catch (nlohmann::json::exception& e) {
sif::warning << "Reading JSON file failed with error " << e.what() << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
return HasReturnvaluesIF::RETURN_OK;
}
return HasFileSystemIF::FILE_DOES_NOT_EXIST;
@ -19,7 +24,12 @@ ReturnValue_t NVMParameterBase::readJsonFile() {
ReturnValue_t NVMParameterBase::writeJsonFile() {
std::ofstream o(fullName);
o << std::setw(4) << json << std::endl;
try {
o << std::setw(4) << json << std::endl;
} catch (nlohmann::json::exception& e) {
sif::warning << "Writing JSON file failed with error " << e.what() << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
return HasReturnvaluesIF::RETURN_OK;
}