Skip to content

Commit

Permalink
JSON readAttribute ReadError
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Apr 1, 2022
1 parent 1ff8192 commit 61550f7
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/IO/JSON/JSONIOHandlerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "openPMD/IO/JSON/JSONIOHandlerImpl.hpp"
#include "openPMD/Datatype.hpp"
#include "openPMD/DatatypeHelpers.hpp"
#include "openPMD/Error.hpp"
#include "openPMD/auxiliary/Filesystem.hpp"
#include "openPMD/auxiliary/Memory.hpp"
#include "openPMD/auxiliary/StringManip.hpp"
Expand Down Expand Up @@ -826,11 +827,15 @@ void JSONIOHandlerImpl::readAttribute(
auto &jsonLoc = obtainJsonContents(writable)["attributes"];
setAndGetFilePosition(writable);
std::string error_msg("[JSON] No such attribute '");
error_msg.append(name)
.append("' in the given location '")
.append(jsonLoc.dump())
.append("'.");
VERIFY_ALWAYS(hasKey(jsonLoc, name), error_msg)
if (!hasKey(jsonLoc, name))
{
throw error::ReadError(
error::AffectedObject::Attribute,
error::Reason::NotFound,
"JSON",
"Tried looking up attribute '" + name +
"' in object: " + jsonLoc.dump());
}
auto &j = jsonLoc[name];
try
{
Expand All @@ -840,9 +845,12 @@ void JSONIOHandlerImpl::readAttribute(
}
catch (json::type_error &)
{
throw std::runtime_error(
"[JSON] The given location does not contain a properly formatted "
"attribute");
throw error::ReadError(
error::AffectedObject::Attribute,
error::Reason::UnexpectedContent,
"JSON",
"No properly formatted attribute with name '" + name +
"' found in object: " + jsonLoc.dump());
}
}

Expand Down

0 comments on commit 61550f7

Please sign in to comment.