Skip to content

Commit

Permalink
Improve ParsedOp error message
Browse files Browse the repository at this point in the history
  • Loading branch information
msmygit committed May 7, 2024
1 parent d05d663 commit c81968b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022-2023 nosqlbench
* Copyright (c) 2022-2024 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,21 +18,21 @@

import io.nosqlbench.adapters.api.activityconfig.yaml.OpData;
import io.nosqlbench.adapters.api.activityconfig.yaml.OpTemplate;
import io.nosqlbench.nb.api.labels.NBLabelSpec;
import io.nosqlbench.nb.api.labels.NBLabels;
import io.nosqlbench.nb.api.config.fieldreaders.DynamicFieldReader;
import io.nosqlbench.nb.api.config.fieldreaders.StaticFieldReader;
import io.nosqlbench.nb.api.config.standard.NBConfigError;
import io.nosqlbench.nb.api.config.standard.NBConfiguration;
import io.nosqlbench.nb.api.errors.OpConfigError;
import io.nosqlbench.nb.api.components.core.NBComponent;
import io.nosqlbench.nb.api.components.core.NBBaseComponent;
import io.nosqlbench.engine.api.templating.ObjectCache;
import io.nosqlbench.engine.api.templating.ParsedTemplateMap;
import io.nosqlbench.engine.api.templating.TypeAndTarget;
import io.nosqlbench.engine.api.templating.binders.ArrayBinder;
import io.nosqlbench.engine.api.templating.binders.ListBinder;
import io.nosqlbench.engine.api.templating.binders.OrderedMapBinder;
import io.nosqlbench.nb.api.components.core.NBBaseComponent;
import io.nosqlbench.nb.api.components.core.NBComponent;
import io.nosqlbench.nb.api.config.fieldreaders.DynamicFieldReader;
import io.nosqlbench.nb.api.config.fieldreaders.StaticFieldReader;
import io.nosqlbench.nb.api.config.standard.NBConfigError;
import io.nosqlbench.nb.api.config.standard.NBConfiguration;
import io.nosqlbench.nb.api.errors.OpConfigError;
import io.nosqlbench.nb.api.labels.NBLabelSpec;
import io.nosqlbench.nb.api.labels.NBLabels;
import io.nosqlbench.virtdata.core.templates.BindPoint;
import io.nosqlbench.virtdata.core.templates.CapturePoint;
import io.nosqlbench.virtdata.core.templates.ParsedTemplateString;
Expand Down Expand Up @@ -1034,8 +1034,8 @@ public Map<String, ParsedOp> getAsSubOps(String fromOpField, SubOpNaming naming)
ParsedOp parsedOp = makeSubOp(fromOpField, String.format(format, i), stmt.toString(), naming);
subOpMap.put(parsedOp.getName(), parsedOp);
} else {
throw new OpConfigError("For sub-ops field " + fromOpField + " of op '" + this.getName() + "', element " +
"types must be of Map or String, not '" + o.getClass().getCanonicalName() + "'");
throw new OpConfigError("For sub-ops field '" + fromOpField + "' of op '" + this.getName() + "'," +
" element types must be of Map or String, not '" + listElem.getClass().getCanonicalName() + "'");
}
}
} else if (o instanceof Map map) {
Expand All @@ -1048,8 +1048,8 @@ public Map<String, ParsedOp> getAsSubOps(String fromOpField, SubOpNaming naming)
ParsedOp subOp = makeSubOp(fromOpField, nameKey.toString(), stmt.toString(), naming);
subOpMap.put(subOp.getName(), subOp);
} else {
throw new OpConfigError("For sub-ops field " + fromOpField + " of op '" + this.getName() + "', element " +
"types must be of Map or String, not '" + o.getClass().getCanonicalName() + "'");
throw new OpConfigError("For sub-ops field '" + fromOpField + "(" + nameKey.toString() + ")' of op '" + this.getName() + "'" +
", element " + "types must be of Map or String, not '" + opref.getClass().getCanonicalName() + "'");
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022-2023 nosqlbench
* Copyright (c) 2020-2024 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -302,6 +302,7 @@ public <T> T getStaticValue(String field, Class<T> classOfT) {
} else if (isConfig(field)) {
return getConfig(field);
}
logger.warn("static field '{}' was requested, but it does not exist", field);
return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 nosqlbench
* Copyright (c) 2020-2024 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -58,4 +58,10 @@ public void testTakeAsNamedTemplates() {

}

@Test
public void testForNullWhenNoFieldFoundWhenCallingStaticValue() {
ParsedTemplateMap ptm = new ParsedTemplateMap("name1", Map.of("string1", "string2"), Map.of(), List.of());
assertThat(ptm.getStaticValue("notfound", String.class)).isNull();
}

}

0 comments on commit c81968b

Please sign in to comment.