From f774053105ca02c6f134356f7151582c22f54075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Fri, 7 Jul 2023 14:58:05 +0200 Subject: [PATCH 1/3] Deal with trailing slashes in file paths Happens in bash completion on BP files since they are folders. --- src/Series.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Series.cpp b/src/Series.cpp index 39c46f30ba..fd2fa3b7ae 100644 --- a/src/Series.cpp +++ b/src/Series.cpp @@ -424,6 +424,11 @@ std::unique_ptr Series::parseInput(std::string filepath) filepath = auxiliary::replace_all(filepath, "\\", "/"); } #endif + if (auxiliary::ends_with(filepath, auxiliary::directory_separator)) + { + filepath = auxiliary::replace_last( + filepath, std::string(&auxiliary::directory_separator, 1), ""); + } auto const pos = filepath.find_last_of(auxiliary::directory_separator); if (std::string::npos == pos) { From 1a4f2c15a93e7790bb9b765da7b53d34d5fcc165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Fri, 7 Jul 2023 15:27:06 +0200 Subject: [PATCH 2/3] Throw better error messages when selecting a bad backend --- .../openPMD/IO/AbstractIOHandlerHelper.hpp | 8 +++++-- src/IO/AbstractIOHandlerHelper.cpp | 22 ++++++++++++++----- src/Series.cpp | 10 +++++++-- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/include/openPMD/IO/AbstractIOHandlerHelper.hpp b/include/openPMD/IO/AbstractIOHandlerHelper.hpp index 95d2d5537e..a5ce7a39be 100644 --- a/include/openPMD/IO/AbstractIOHandlerHelper.hpp +++ b/include/openPMD/IO/AbstractIOHandlerHelper.hpp @@ -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. @@ -51,7 +52,8 @@ std::unique_ptr 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. @@ -65,6 +67,7 @@ std::unique_ptr 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. @@ -75,7 +78,8 @@ std::unique_ptr 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 createIOHandler( diff --git a/src/IO/AbstractIOHandlerHelper.cpp b/src/IO/AbstractIOHandlerHelper.cpp index c58528f568..4cd74a4de2 100644 --- a/src/IO/AbstractIOHandlerHelper.cpp +++ b/src/IO/AbstractIOHandlerHelper.cpp @@ -71,7 +71,8 @@ std::unique_ptr createIOHandler( std::string originalExtension, MPI_Comm comm, - json::TracingJSON options) + json::TracingJSON options, + std::string const &pathAsItWasSpecifiedInTheConstructor) { (void)options; switch (format) @@ -124,9 +125,14 @@ std::unique_ptr createIOHandler( 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 @@ -137,7 +143,8 @@ std::unique_ptr createIOHandler( Access access, Format format, std::string originalExtension, - json::TracingJSON options) + json::TracingJSON options, + std::string const &pathAsItWasSpecifiedInTheConstructor) { (void)options; switch (format) @@ -190,7 +197,9 @@ std::unique_ptr createIOHandler( "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 + "'."); } } @@ -205,6 +214,7 @@ std::unique_ptr createIOHandler( access, format, std::move(originalExtension), - json::TracingJSON(json::ParsedConfig{})); + json::TracingJSON(json::ParsedConfig{}), + ""); } } // namespace openPMD diff --git a/src/Series.cpp b/src/Series.cpp index fd2fa3b7ae..99e654b33a 100644 --- a/src/Series.cpp +++ b/src/Series.cpp @@ -2313,7 +2313,8 @@ Series::Series( input->format, input->filenameExtension, comm, - optionsJson); + optionsJson, + filepath); init(std::move(handler), std::move(input)); json::warnGlobalUnusedOptions(optionsJson); } @@ -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); } From 7542a3f0adb392d8445a8ba3e3ca8bf186b762f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Mon, 10 Jul 2023 11:26:03 +0200 Subject: [PATCH 3/3] Adapt CoreTest to new error message --- test/CoreTest.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/CoreTest.cpp b/test/CoreTest.cpp index 8c34faf29c..224596864e 100644 --- a/test/CoreTest.cpp +++ b/test/CoreTest.cpp @@ -1035,13 +1035,16 @@ TEST_CASE("no_file_ending", "[core]") { REQUIRE_THROWS_WITH( Series("./new_openpmd_output", Access::CREATE), - Catch::Equals("Unknown file format! Did you specify a file ending?")); + Catch::Equals("Unknown file format! Did you specify a file ending? " + "Specified file name was './new_openpmd_output'.")); REQUIRE_THROWS_WITH( Series("./new_openpmd_output_%T", Access::CREATE), - Catch::Equals("Unknown file format! Did you specify a file ending?")); + Catch::Equals("Unknown file format! Did you specify a file ending? " + "Specified file name was './new_openpmd_output_%T'.")); REQUIRE_THROWS_WITH( Series("./new_openpmd_output_%05T", Access::CREATE), - Catch::Equals("Unknown file format! Did you specify a file ending?")); + Catch::Equals("Unknown file format! Did you specify a file ending? " + "Specified file name was './new_openpmd_output_%05T'.")); { Series( "../samples/no_extension_specified",