improve error for driver adapter not found

This commit is contained in:
Jonathan Shook 2022-06-28 18:23:22 -05:00
parent a6df79c322
commit a05dbc834a
2 changed files with 42 additions and 10 deletions

View File

@ -26,6 +26,7 @@ import io.nosqlbench.engine.core.annotation.Annotators;
import io.nosqlbench.nb.annotations.Maturity;
import io.nosqlbench.nb.api.annotations.Annotation;
import io.nosqlbench.nb.api.annotations.Layer;
import io.nosqlbench.nb.api.config.standard.ConfigSuggestions;
import io.nosqlbench.nb.api.errors.BasicError;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -323,7 +324,12 @@ public class ScenarioController {
.setMaturity(this.minMaturity)
.load(activityDef)
.orElseThrow(
() -> new RuntimeException("Driver for '" + activityDef + "' was not found.")
() -> new RuntimeException("Driver for '" + activityDef + "' was not found." +
"\nYou can use --list-drivers to see what drivers are supported in this runtime." +
ConfigSuggestions.suggestAlternates(
new ActivityTypeLoader().getAllSelectors(),activityDef.getActivityType(),4)
.orElse("")
)
);
executor = new ActivityExecutor(

View File

@ -24,25 +24,51 @@ import java.util.stream.Collectors;
public class ConfigSuggestions {
public static Optional<String> getForParam(ConfigModel model, String param) {
return suggestAlternateCase(model,param)
.or(() -> suggestAlternates(model,param,4));
return suggestAlternateCase(model, param)
.or(() -> suggestAlternates(model, param, 4));
}
private static Optional<String> suggestAlternateCase(ConfigModel model, String param) {
for (String cname : model.getNamedParams().keySet()) {
if (cname.equalsIgnoreCase(param)) {
return Optional.of("Did you mean '" + cname + "'?");
return Optional.of(" Did you mean '" + cname + "'?");
}
}
return Optional.empty();
}
private static Optional<String> suggestAlternates(ConfigModel model, String param, int maxDistance) {
public static Optional<String> suggestAlternates(Set<String> candidates, String provided, int maxDistance) {
Set<String>[] sorted = new Set[maxDistance+1];
for (int i = 0; i < sorted.length; i++) {
sorted[i]=new HashSet<String>();
}
for (String candidate : candidates) {
int distance = LevenshteinDistance.getDefaultInstance().apply(provided, candidate);
if (distance<=maxDistance) {
sorted[distance].add(candidate);
}
}
for (Set<String> set : sorted) {
if (set.size()>1) {
return Optional.of(" Did you mean one of '" + String.join("','", set) + "' ?");
} else if (set.size()==1) {
return Optional.of(" Did you mean '" + set.stream().findFirst().get() + "' ?");
}
}
return Optional.empty();
}
private static Optional<String> suggestAlternates(
ConfigModel model,
String param,
int maxDistance
) {
Map<Integer, Set<String>> suggestions = new HashMap<>();
for (String candidate : model.getNamedParams().keySet()) {
try {
Integer distance = LevenshteinDistance.getDefaultInstance().apply(param, candidate);
if (distance>maxDistance) {
if (distance > maxDistance) {
continue;
}
Set<String> strings = suggestions.computeIfAbsent(distance, d -> new HashSet<>());
@ -55,12 +81,12 @@ public class ConfigSuggestions {
ArrayList<Integer> params = new ArrayList<>(suggestions.keySet());
Collections.sort(params);
List<Set<String>> orderedSets = params.stream().map(suggestions::get).collect(Collectors.toList());
if (orderedSets.size()==0) {
if (orderedSets.size() == 0) {
return Optional.empty();
} else if (orderedSets.get(0).size()==1) {
return Optional.of("Did you mean '" + orderedSets.get(0).stream().findFirst().get() +"'?");
} else if (orderedSets.get(0).size() == 1) {
return Optional.of(" Did you mean '" + orderedSets.get(0).stream().findFirst().get() + "'?");
} else {
return Optional.of("Did you mean one of " + orderedSets.get(0).toString() + "?\n");
return Optional.of(" Did you mean one of " + orderedSets.get(0).toString() + "?\n");
}
}
}