-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Description
Describe the bug
registerDynamicSetting() javadocs state:
Settings can be of Node Scope or Index Scope.
However, this is a "must". And regardless of the scope, some of this code isn't reachable:
OpenSearch/server/src/main/java/org/opensearch/common/settings/SettingsModule.java
Lines 188 to 203 in e08d57b
| public boolean registerDynamicSetting(Setting<?> setting) { | |
| try { | |
| registerSetting(setting); | |
| if (setting.hasNodeScope()) { | |
| return clusterSettings.registerSetting(setting); | |
| } | |
| if (setting.hasIndexScope()) { | |
| return indexScopedSettings.registerSetting(setting); | |
| } | |
| logger.info("Registered new Setting: " + setting.getKey() + " successfully "); | |
| } catch (Exception e) { | |
| logger.error("Could not register setting " + setting.getKey()); | |
| throw new SettingsException("Could not register setting:" + setting.getKey()); | |
| } | |
| return false; | |
| } |
In the case the setting has neither Node nor Index scope, line 190 calls registerSetting() which contains this code:
if (setting.hasNodeScope() || setting.hasIndexScope()) {
if (setting.hasNodeScope()) {
// ...
}
if (setting.hasIndexScope()) {
// ...
}
} else {
throw new IllegalArgumentException("No scope found for setting [" + setting.getKey() + "]");
}This jumps immediately to the catch block with an unhelpful log message.
In the case it has Node Scope it passes the first check but returns at line 192.
In the case it has Index Scope and not Node Scope it returns at line 195. However it never reaches this line if it has both Index Scope and Node Scope.
There is no possibility of it ever reaching the log message at line 197.
To Reproduce
Steps to reproduce the behavior:
- Attempt to register a setting without either Node Scope or Index Scope
- Observe the failure to register
- Wonder why, edit the code to produce a stack trace
- Find the IllegalArgumentExcxeption that gets swallowed in the catch block.
Expected behavior
Log warnings that clearly state why it didn't work (e.g., you didn't have the correct scope). I believe including the caught exception in the re-thrown exception would provide a "Caused By" link to clarify it, but haven't tested this.