Skip to content
Snippets Groups Projects
Commit 07687a2d authored by Peterson, Peter's avatar Peterson, Peter
Browse files

Warn user and ignore *FilterChannel properties

This will allow users to have logging again
parent 994efd76
No related branches found
No related tags found
No related merge requests found
...@@ -325,6 +325,48 @@ void ConfigServiceImpl::setBaseDirectory() { ...@@ -325,6 +325,48 @@ void ConfigServiceImpl::setBaseDirectory() {
#endif #endif
} }
namespace {
// look for specific keys and throw an exception if one is found
std::string checkForBadConfigOptions(const std::string &filename,
const std::string &propertiesString) {
std::stringstream stream(propertiesString);
std::stringstream resultPropertiesString;
std::string line;
int line_num = 0;
while (std::getline(stream, line)) {
line_num += 1; // increment early
bool is_ok = true;
// Check for common errors. Empty lines are ok, things that are a key
// without a value are a critical failure. Forbidden keys are just commented
// out.
if (line.empty() || (Kernel::Strings::strip(line)[0] == '#')) {
// do nothing
} else if (line.find("FilterChannel") != std::string::npos) {
is_ok = false;
}
// Print warning to error channel and comment out offending line
if (!is_ok) {
const auto end = line.find("=");
std::cerr << "Encontered invalid key \"";
if (end != std::string::npos) {
std::cerr << Kernel::Strings::strip(line.substr(0, end));
} else {
std::cerr << Kernel::Strings::strip(line);
}
std::cerr << "\" in " << filename << " on line " << line_num << std::endl;
// comment out the property
resultPropertiesString << '#';
}
// copy over the line
resultPropertiesString << line << '\n';
}
return resultPropertiesString.str();
}
} // end of anonymous namespace
/** Loads the config file provided. /** Loads the config file provided.
* If the file contains logging setup instructions then these will be used to * If the file contains logging setup instructions then these will be used to
*setup the logging framework. *setup the logging framework.
...@@ -358,6 +400,9 @@ void ConfigServiceImpl::loadConfig(const std::string &filename, ...@@ -358,6 +400,9 @@ void ConfigServiceImpl::loadConfig(const std::string &filename,
} }
} }
// verify the contents and comment out offending lines
temp = checkForBadConfigOptions(filename, temp);
// store the property string // store the property string
if ((append) && (!m_PropertyString.empty())) { if ((append) && (!m_PropertyString.empty())) {
m_PropertyString = m_PropertyString + "\n" + temp; m_PropertyString = m_PropertyString + "\n" + temp;
......
...@@ -483,6 +483,7 @@ public: ...@@ -483,6 +483,7 @@ public:
writer << "\n"; writer << "\n";
writer << "mantid.thorax = 10\n"; writer << "mantid.thorax = 10\n";
writer << "# This comment line\n"; writer << "# This comment line\n";
writer << " # This is an indented comment line\n";
writer << "key.withnospace=5\n"; writer << "key.withnospace=5\n";
writer << "key.withnovalue"; writer << "key.withnovalue";
writer.close(); writer.close();
...@@ -512,11 +513,12 @@ public: ...@@ -512,11 +513,12 @@ public:
} }
reader.close(); reader.close();
TS_ASSERT_EQUALS(prop_lines.size(), 4); TS_ASSERT_EQUALS(prop_lines.size(), 5);
TS_ASSERT_EQUALS(prop_lines[0], "mantid.legs=6"); TS_ASSERT_EQUALS(prop_lines[0], "mantid.legs=6");
TS_ASSERT_EQUALS(prop_lines[1], ""); TS_ASSERT_EQUALS(prop_lines[1], "");
TS_ASSERT_EQUALS(prop_lines[2], "# This comment line"); TS_ASSERT_EQUALS(prop_lines[2], "# This comment line");
TS_ASSERT_EQUALS(prop_lines[3], "key.withnospace=5"); TS_ASSERT_EQUALS(prop_lines[3], " # This is an indented comment line");
TS_ASSERT_EQUALS(prop_lines[4], "key.withnospace=5");
// Clean up // Clean up
prop_file.remove(); prop_file.remove();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment