Skip to content

Commit

Permalink
Added catch for error from parsing json
Browse files Browse the repository at this point in the history
- If for some reason the index file on IDAaaS is currupted (eg. being updated) then the error is caught
- Allows for the search to continue on the archive

Co-authored-by: Jonathan Haigh <jonathan.haigh@stfc.ac.uk>
  • Loading branch information
GuiMacielPereira and jhaigh0 committed May 9, 2024
1 parent c5d73a2 commit 46101db
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Framework/API/src/FileFinder.cpp
Expand Up @@ -32,6 +32,7 @@
#include <boost/algorithm/string.hpp>

#include <filesystem>
#include <json //value.h>

namespace {
/// static logger object
Expand Down Expand Up @@ -668,6 +669,11 @@ FileFinderImpl::getISISInstrumentDataCachePath(const std::string &cachePathToSea
} catch (const std::invalid_argument &e) {
errors += "Data cache: " + std::string(e.what());
return API::Result<std::string>("", errors);

} catch (const Json::Exception &e) {
errors += "Data cache: Failed parsing to JSON: " + std::string(e.what()) +
"Error likely due to accessing instrument index file while it was being updated on IDAaaS.";
return API::Result<std::string>("", errors);
}

if (!std::filesystem::exists(parentDirPath)) {
Expand Down
2 changes: 1 addition & 1 deletion Framework/API/src/ISISInstrumentDataCache.cpp
Expand Up @@ -21,7 +21,7 @@ std::string Mantid::API::ISISInstrumentDataCache::getFileParentDirectoryPath(std
std::string jsonPath = m_dataCachePath + "/" + instrName + "/" + instrName + "_index.json";
std::ifstream ifstrm{jsonPath};
if (!ifstrm) {
throw std::invalid_argument("Error opennig instrument index file: " + jsonPath);
throw std::invalid_argument("Could not open index file: " + jsonPath);
}

// Read directory path from json file
Expand Down

0 comments on commit 46101db

Please sign in to comment.