use of org.yaml.snakeyaml.composer.ComposerException in project toolkit by googleapis.
the class ConfigYamlReader method generateConfigNode.
public FieldConfigNode generateConfigNode(File file, ConfigHelper helper) {
int initialErrorCount = helper.getErrorCount();
String input;
try {
input = Files.toString(file, Charsets.UTF_8);
} catch (IOException e) {
helper.error("Cannot read configuration file: %s", e.getMessage());
return null;
}
if (input.trim().isEmpty()) {
helper.error("Empty YAML document");
return null;
}
Node tree;
try {
tree = new Yaml().compose(new StringReader(input));
} catch (ComposerException e) {
helper.error(e.getProblemMark(), "Parsing error: %s", e.getMessage());
return null;
} catch (Exception e) {
helper.error("Parsing error: %s", e.getMessage());
return null;
}
if (tree == null) {
helper.error("Parsing error");
return null;
}
if (!(tree instanceof MappingNode)) {
helper.error(tree, "Expected a map as a root object.");
return null;
}
List<String> lines = Splitter.on(System.lineSeparator()).splitToList(input);
ConfigNode configNode = new ConfigYamlNodeReader(lines, helper).readMessageNode((MappingNode) tree, ConfigProto.getDescriptor());
return helper.getErrorCount() == initialErrorCount ? new FieldConfigNode(0, "").setChild(configNode) : null;
}
Aggregations