From 340b3dc45019dee304b82d7a0c1bf275138be2de Mon Sep 17 00:00:00 2001 From: Markus Blatt Date: Tue, 27 Jun 2023 14:02:22 +0200 Subject: [PATCH] Quote file path if file not found to make trailing ws apparent. For an include directive with a path with trailing whitespace, e.g. ``` INCLUDE '/home/model/../include/file_trailing_ws.ext ' / ``` the current error message ``` Error: No such file: /home/model/../include/file_trailing_ws.ext ``` is changed to ``` File '/home/model/../include/file_trailing_ws.ext ' included via INCLUDE directive does not exist. Note that the file name contains trailing whitespace. ``` This should at least make it easier to spot this error. An alternative would be to trim the string, but people using quotes should actually know what they are doing. --- src/opm/input/eclipse/Parser/Parser.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/opm/input/eclipse/Parser/Parser.cpp b/src/opm/input/eclipse/Parser/Parser.cpp index 280cd8eaf..b3df5a30c 100644 --- a/src/opm/input/eclipse/Parser/Parser.cpp +++ b/src/opm/input/eclipse/Parser/Parser.cpp @@ -66,6 +66,7 @@ #include #include #include +#include #include #include @@ -688,7 +689,19 @@ std::optional ParserState::getIncludeFilePath( std::strin try { includeFilePath = std::filesystem::canonical(includeFilePath); } catch (const std::filesystem::filesystem_error& fs_error) { - parseContext.handleError( ParseContext::PARSE_MISSING_INCLUDE , fmt::format("No such file: {}", includeFilePath.string()), {}, errors); + const auto& str_rep = includeFilePath.string(); + std::regex trim_regex("^\\s+|\\s+$"); + const auto& trimmed_rep = std::regex_replace(str_rep, trim_regex, ""); + std::string extra_info; + if (str_rep.size() != trimmed_rep.size()) { + extra_info = " Note that the file name contains trailing whitespace."; + } + parseContext.handleError( ParseContext::PARSE_MISSING_INCLUDE , + fmt::format("File '{}' included via INCLUDE" + " directive does not exist.{}", + str_rep, + extra_info), + {}, errors); return {}; }