Skip to content

Commit 5dd192a

Browse files
committed
Improve error if unable to open meta.json file
Closes jameseh96#3. Previously, if the file could not be opened an exception would be thrown from in nlohmann json, with a misleading message. Check the state of the ifstream before handing off to parse json.
1 parent 9182f7a commit 5dd192a

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/pdu/block/index.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ void Index::load(std::shared_ptr<Resource> res) {
175175

176176
{
177177
std::ifstream metaF(metaPath.string(), std::ios::in);
178+
if (!metaF.good()) {
179+
throw std::runtime_error("Failed to open \"" + metaPath.string() +
180+
"\" when trying to parse index meta");
181+
}
178182
meta = nlohmann::json::parse(metaF);
179183
metaF.close();
180184
}

0 commit comments

Comments
 (0)