Merge pull request #1960 from cognitree/better-error-on-scenario-step-selection

Better error when users select a scenario step without setting the scenario
This commit is contained in:
Jonathan Shook 2024-06-18 16:25:19 -05:00 committed by GitHub
commit 82e60d3f2a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 2 deletions

View File

@ -234,4 +234,11 @@ public class NBCLIScenarioPreprocessorTest {
.isThrownBy(() -> NBCLIScenarioPreprocessor.splitCommand(unclosedQuoteCmd)) .isThrownBy(() -> NBCLIScenarioPreprocessor.splitCommand(unclosedQuoteCmd))
.withMessageContaining("Unclosed quote found in scenario cmd"); .withMessageContaining("Unclosed quote found in scenario cmd");
} }
@Test
public void testThatSuggestionsAreShownForDirectStepNameUsage() {
assertThatExceptionOfType(BasicError.class)
.isThrownBy(() -> new NBCLIOptions(new String[]{"scenario_test", "schema"}, NBCLIOptions.Mode.ParseAllOptions))
.withMessageContainingAll("default.schema", "schema_only.schema");
}
} }

View File

@ -133,8 +133,20 @@ public class NBCLIScenarioPreprocessor {
if (nameparts.length==1) { if (nameparts.length==1) {
Map<String, String> namedScenario = scenarios.getNamedScenario(scenarioName); Map<String, String> namedScenario = scenarios.getNamedScenario(scenarioName);
if (namedScenario==null) { if (namedScenario==null) {
throw new BasicError("Unable to find named scenario '" + scenarioName + "' in workload '" + workloadName List<String> matchingSteps = new LinkedList<>();
+ "', but you can pick from one of: " + String.join(", ", scenarios.getScenarioNames())); for (String scenario : scenarios.getScenarioNames()) {
Map<String, String> selectedScenario = scenarios.getNamedScenario(scenario);
if (selectedScenario.containsKey(scenarioName)) {
matchingSteps.add(scenario + "." + scenarioName);
}
}
if (matchingSteps.isEmpty()) {
throw new BasicError("Unable to find named scenario '" + scenarioName + "' in workload '" + workloadName
+ "', but you can pick from one of: " + String.join(", ", scenarios.getScenarioNames()));
} else {
throw new BasicError("Unable to find named scenario '" + scenarioName + "' in workload '" + workloadName
+ "', you might be looking for one of these scenario steps: " + String.join(", ", matchingSteps));
}
} }
namedSteps.putAll(namedScenario); namedSteps.putAll(namedScenario);
} else { } else {