From 6c7668c8a7e8666db0b79d7f90893bdae1d64da8 Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Wed, 18 Sep 2024 13:25:30 -0700 Subject: [PATCH] `ParmParse:addFile`: User-Friendly Error (#4156) ## Summary If a file added via `ParmParse:addFile` does not exist, we did not yet receive a user-friendly error message. This fixes this in a way that does not hammer the file system from all MPI ranks. ## Additional background Follow-up to #2842 #2936 #3440 X-ref: https://github.com/ECP-WarpX/WarpX/issues/5283 https://github.com/ECP-WarpX/impactx/pull/704 --- Src/Base/AMReX_ParmParse.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Src/Base/AMReX_ParmParse.cpp b/Src/Base/AMReX_ParmParse.cpp index 9d61fad89f..4e69901d5e 100644 --- a/Src/Base/AMReX_ParmParse.cpp +++ b/Src/Base/AMReX_ParmParse.cpp @@ -1069,12 +1069,23 @@ ParmParse::prefixedName (const std::string_view& str) const void ParmParse::addfile (std::string const& filename) { #ifdef AMREX_USE_MPI + // this is required because we will BCast the file content in sub-function calls if (ParallelDescriptor::Communicator() == MPI_COMM_NULL) { throw std::runtime_error("ParmParse::addfile: AMReX must be initialized"); } #endif + // check the file exists and give a user-friendly error + if (ParallelDescriptor::IOProcessor()) + { + AMREX_ALWAYS_ASSERT_WITH_MESSAGE( + FileExists(filename), + "ParmParse::addfile: file does not exist: " + filename + ); + } + + // add the file auto file = FileKeyword; std::vector val{{filename}}; addDefn(file, val, g_table);