Skip to content

Commit

Permalink
Throw better error messages when selecting a bad backend
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Jul 7, 2023
1 parent 2dd2e4e commit ada9c30
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
8 changes: 6 additions & 2 deletions include/openPMD/IO/AbstractIOHandlerHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace openPMD
* @param comm MPI communicator used for IO.
* @param options JSON-formatted option string, to be interpreted by
* the backend.
* @param pathAsItWasSpecifiedInTheConstructor For error messages.
* @tparam JSON Substitute for nlohmann::json. Templated to avoid
including nlohmann::json in a .hpp file.
* @return Smart pointer to created IOHandler.
Expand All @@ -51,7 +52,8 @@ std::unique_ptr<AbstractIOHandler> createIOHandler(
Format format,
std::string originalExtension,
MPI_Comm comm,
JSON options);
JSON options,
std::string const &pathAsItWasSpecifiedInTheConstructor);
#endif

/** Construct an appropriate specific IOHandler for the desired IO mode.
Expand All @@ -65,6 +67,7 @@ std::unique_ptr<AbstractIOHandler> createIOHandler(
* specified by the user.
* @param options JSON-formatted option string, to be interpreted by
* the backend.
* @param pathAsItWasSpecifiedInTheConstructor For error messages.
* @tparam JSON Substitute for nlohmann::json. Templated to avoid
including nlohmann::json in a .hpp file.
* @return Smart pointer to created IOHandler.
Expand All @@ -75,7 +78,8 @@ std::unique_ptr<AbstractIOHandler> createIOHandler(
Access access,
Format format,
std::string originalExtension,
JSON options = JSON());
JSON options,
std::string const &pathAsItWasSpecifiedInTheConstructor);

// version without configuration to use in AuxiliaryTest
std::unique_ptr<AbstractIOHandler> createIOHandler(
Expand Down
22 changes: 16 additions & 6 deletions src/IO/AbstractIOHandlerHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ std::unique_ptr<AbstractIOHandler> createIOHandler<json::TracingJSON>(
std::string originalExtension,

MPI_Comm comm,
json::TracingJSON options)
json::TracingJSON options,
std::string const &pathAsItWasSpecifiedInTheConstructor)
{
(void)options;
switch (format)
Expand Down Expand Up @@ -124,9 +125,14 @@ std::unique_ptr<AbstractIOHandler> createIOHandler<json::TracingJSON>(
std::move(options),
"ssc",
std::move(originalExtension));
case Format::JSON:
throw error::WrongAPIUsage(
"JSON backend not available in parallel openPMD.");
default:
throw std::runtime_error(
"Unknown file format! Did you specify a file ending?");
throw error::WrongAPIUsage(
"Unknown file format! Did you specify a file ending? Specified "
"file name was '" +
pathAsItWasSpecifiedInTheConstructor + "'.");
}
}
#endif
Expand All @@ -137,7 +143,8 @@ std::unique_ptr<AbstractIOHandler> createIOHandler<json::TracingJSON>(
Access access,
Format format,
std::string originalExtension,
json::TracingJSON options)
json::TracingJSON options,
std::string const &pathAsItWasSpecifiedInTheConstructor)
{
(void)options;
switch (format)
Expand Down Expand Up @@ -190,7 +197,9 @@ std::unique_ptr<AbstractIOHandler> createIOHandler<json::TracingJSON>(
"JSON", path, access);
default:
throw std::runtime_error(
"Unknown file format! Did you specify a file ending?");
"Unknown file format! Did you specify a file ending? Specified "
"file name was '" +
pathAsItWasSpecifiedInTheConstructor + "'.");
}
}

Expand All @@ -205,6 +214,7 @@ std::unique_ptr<AbstractIOHandler> createIOHandler(
access,
format,
std::move(originalExtension),
json::TracingJSON(json::ParsedConfig{}));
json::TracingJSON(json::ParsedConfig{}),
"");
}
} // namespace openPMD
10 changes: 8 additions & 2 deletions src/Series.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2313,7 +2313,8 @@ Series::Series(
input->format,
input->filenameExtension,
comm,
optionsJson);
optionsJson,
filepath);
init(std::move(handler), std::move(input));
json::warnGlobalUnusedOptions(optionsJson);
}
Expand All @@ -2330,7 +2331,12 @@ Series::Series(
auto input = parseInput(filepath);
parseJsonOptions(optionsJson, *input);
auto handler = createIOHandler(
input->path, at, input->format, input->filenameExtension, optionsJson);
input->path,
at,
input->format,
input->filenameExtension,
optionsJson,
filepath);
init(std::move(handler), std::move(input));
json::warnGlobalUnusedOptions(optionsJson);
}
Expand Down

0 comments on commit ada9c30

Please sign in to comment.