- final List<YangTextSchemaSource> yangTextSchemaSources = forResources(yangResourceNameToContent);
- for (final YangTextSchemaSource yangTextSchemaSource : yangTextSchemaSources) {
- reactor.addSource(YangStatementStreamSource.create(yangTextSchemaSource));
+ for (final YangTextSchemaSource yangTextSchemaSource : forResources(yangResourceNameToContent)) {
+ final String resourceName = yangTextSchemaSource.getIdentifier().getName();
+ try {
+ reactor.addSource(YangStatementStreamSource.create(yangTextSchemaSource));
+ } catch (final IOException e) {
+ throw new CpsException("Failed to read yang resource.",
+ String.format("Exception occurred on reading resource %s.", resourceName), e);
+ } catch (final YangSyntaxErrorException e) {
+ throw new ModelValidationException("Yang resource is invalid.",
+ String.format(
+ "Yang syntax validation failed for resource %s:%n%s", resourceName, e.getMessage()), e);
+ }
+ }
+ try {
+ return reactor.buildEffective();
+ } catch (final ReactorException e) {
+ final List<String> resourceNames = yangResourceNameToContent.keySet().stream().collect(Collectors.toList());
+ Collections.sort(resourceNames);
+ throw new ModelValidationException("Invalid schema set.",
+ String.format("Effective schema context build failed for resources %s.", resourceNames.toString()),
+ e);