provide better error messages for malformed yaml

This commit is contained in:
Jonathan Shook 2021-04-08 15:03:54 -05:00
parent 5355edf759
commit 8143a2c275
6 changed files with 59 additions and 43 deletions

View File

@ -45,11 +45,11 @@ public class RawStmtsLoader {
try {
Optional<Content<?>> oyaml = NBIO.all().prefix(searchPaths).name(path).extension(YAML_EXTENSIONS).first();
data = oyaml.map(Content::asString).orElseThrow(() -> new BasicError("Unable to load " + path));
return loadString(logger, data);
} catch (Exception e) {
throw new RuntimeException("error while reading file " + path, e);
}
return loadString(logger, data);
}
private RawStmtsDocList parseYaml(Logger logger, String data) {

View File

@ -267,6 +267,8 @@ public class NBCLIScenarioParser {
for (Path yamlPath : yamlPathList) {
try {
String referenced = yamlPath.toString();
if (referenced.startsWith("/")) {
@ -302,7 +304,7 @@ public class NBCLIScenarioParser {
templates = matchTemplates(line, templates);
}
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
@ -323,6 +325,10 @@ public class NBCLIScenarioParser {
String description = stmts.getDescription();
workloadDescriptions.add(new WorkloadDesc(referenced, scenarioNames, sortedTemplates, description, ""));
}
} catch (Exception e) {
throw new RuntimeException("Error while scanning path '" + yamlPath.toString() + "':" + e.getMessage(), e);
}
}
Collections.sort(workloadDescriptions);

View File

@ -84,8 +84,12 @@ public class RawYamlStatementLoaderTest {
assertThat(blocks).hasSize(1);
RawStmtsBlock rawStmtsBlock = blocks.get(0);
assertThat(rawStmtsBlock.getName()).isEqualTo("block0");
}
@Test
public void testErrorMsg() {
RawStmtsLoader ysl = new RawStmtsLoader();
RawStmtsDocList erthing = ysl.loadPath(logger, "testdocs/badyamlfile.yaml");
}
}

View File

@ -0,0 +1,2 @@
# This is just a testing file too.
description: This is just a testing file too

View File

@ -8,9 +8,13 @@ import java.util.List;
public class NBCLIScenarios {
public static void printWorkloads(boolean includeScenarios,
String... includes) {
List<WorkloadDesc> workloads =
NBCLIScenarioParser.getWorkloadsWithScenarioScripts(true, includes);
List<WorkloadDesc> workloads = List.of();
try {
workloads= NBCLIScenarioParser.getWorkloadsWithScenarioScripts(true, includes);
} catch (Exception e) {
throw new RuntimeException("Error while getting workloads:" + e.getMessage(), e);
}
for (WorkloadDesc workload : workloads) {
System.out.println(workload.toMarkdown(includeScenarios));
}

View File

@ -41,7 +41,7 @@ public class NBCliIntegrationTests {
invoker.setLogDir("logs/test");
ProcessResult result = invoker.run(
"workload-test", 15, java, "-jar",
JARNAME, "--logs-dir", "logs/test", "--list-workloads"
JARNAME, "--logs-dir", "logs/test", "--list-workloads", "--show-stacktraces"
);
System.out.println(result.getStdoutData());
System.out.println(result.getStderrData());