@@ -284,12 +284,15 @@ void GOptions::printOptionOrSwitchHelp(const std::string& tag) const {
284284// Private method: see header. Kept undocumented here to avoid duplicate param docs.
285285vector<string> GOptions::findYamls (int argc, char * argv[]) {
286286 vector<string> yaml_files;
287+ auto ends_with = [](const string& s, const string& suffix) {
288+ return s.size () >= suffix.size () &&
289+ s.compare (s.size () - suffix.size (), suffix.size (), suffix) == 0 ;
290+ };
287291 for (int i = 1 ; i < argc; i++) {
288292 string arg = argv[i];
289- size_t pos = arg.find (" .yaml" );
290- if (pos != string::npos) yaml_files.push_back (arg);
291- pos = arg.find (" .yml" );
292- if (pos != string::npos) yaml_files.push_back (arg);
293+ // Match a trailing .yaml/.yml extension, not any substring, so option values such as
294+ // -prefix=run.yaml.bak are not mistaken for input files (and silently dropped).
295+ if (ends_with (arg, " .yaml" ) || ends_with (arg, " .yml" )) yaml_files.push_back (arg);
293296 }
294297 return yaml_files;
295298}
@@ -310,6 +313,11 @@ void GOptions::setOptionsValuesFromYamlFile(const std::string& yaml) {
310313 try {
311314 config = YAML::LoadFile (yaml);
312315 }
316+ catch (YAML ::BadFile& e) {
317+ cerr << FATALERRORL << " Cannot open yaml file " << YELLOWHHL << yaml << RSTHHR
318+ << " . Check the path and spelling." << endl;
319+ exit (EC__YAML_PARSING_ERROR );
320+ }
313321 catch (YAML ::ParserException& e) {
314322 cerr << FATALERRORL << " Error parsing " << YELLOWHHL << yaml << RSTHHR
315323 << " yaml file." << endl;
0 commit comments