eclipse-esmf / esmf-sdk

Load Aspect Models and their artifacts as Java code; share components to realize SAMM as code
https://eclipse-esmf.github.io/esmf-developer-guide/index.html
Mozilla Public License 2.0
25 stars 12 forks source link

[TASK] Provide better error messages for resolution (was: Referenced model file searched in wrong folder) #421

Open bs-jokri opened 1 year ago

bs-jokri commented 1 year ago

Describe the bug

When I try to validate the model

https://github.com/eclipse-tractusx/sldt-semantic-models/pull/259/files#diff-6e5ed56aa133ea210c3299732b33fa035cc2f7a8cfebb123a4e0207e18d9ad1f

It tries to resolve a characteristic from the model

https://github.com/eclipse-tractusx/sldt-semantic-models/blob/main/io.catenax.shared.shopfloor_information_types/1.0.0/ShopfloorInformationTypes.ttl

And I receive the error message

org.eclipse.esmf.aspectmodel.resolver.ModelResolutionException: Could not resolve [urn:samm:org.eclipse.esmf.samm:meta-model:2.0.0#Aspect, urn:samm:org.eclipse.esmf.samm:meta-model:2.0.0#dataType, urn:samm:org.eclipse.esmf.samm:meta-model:2.0.0#Entity, urn:samm:io.catenax.shared.message_header:1.0.0#header, urn:samm:io.catenax.shared.shopfloor_information_types:1.0.0#IntegerValueCharacteristic, urn:samm:io.catenax.shared.shopfloor_information_types:1.0.0#versionDataModel, urn:samm:io.catenax.shared.message_header:1.0.0#UuidCharacteristic, urn:samm:org.eclipse.esmf.samm:characteristic:2.0.0#List, urn:samm:org.eclipse.esmf.samm:meta-model:2.0.0#Characteristic, urn:samm:org.eclipse.esmf.samm:meta-model:2.0.0#optional, urn:samm:org.eclipse.esmf.samm:characteristic:2.0.0#Timestamp, urn:samm:org.eclipse.esmf.samm:meta-model:2.0.0#Property, urn:samm:org.eclipse.esmf.samm:meta-model:2.0.0#preferredName, urn:samm:org.eclipse.esmf.samm:meta-model:2.0.0#description, urn:samm:org.eclipse.esmf.samm:meta-model:2.0.0#property, urn:samm:org.eclipse.esmf.samm:meta-model:2.0.0#operations, urn:samm:org.eclipse.esmf.samm:meta-model:2.0.0#properties, urn:samm:org.eclipse.esmf.samm:characteristic:2.0.0#values, urn:samm:io.catenax.shared.shopfloor_information_types:1.0.0#communicationMode, urn:samm:org.eclipse.esmf.samm:characteristic:2.0.0#Enumeration, urn:samm:org.eclipse.esmf.samm:meta-model:2.0.0#exampleValue, urn:samm:org.eclipse.esmf.samm:meta-model:2.0.0#characteristic, urn:samm:org.eclipse.esmf.samm:meta-model:2.0.0#events, urn:samm:io.catenax.shared.shopfloor_information_types:1.0.0#TimeValueCharacteristic]

at org.eclipse.esmf.aspectmodel.resolver.AspectModelResolver.resolveAspectModel(AspectModelResolver.java:188)

at org.eclipse.esmf.aspectmodel.resolver.AspectModelResolver.resolveAspectModel(AspectModelResolver.java:156)

at org.eclipse.esmf.aspectmodel.resolver.AspectModelResolver.lambda$resolveAspectModel$1(AspectModelResolver.java:133)

at io.vavr.control.Try.flatMapTry(Try.java:490)

at io.vavr.control.Try.flatMap(Try.java:472)

at org.eclipse.esmf.aspectmodel.resolver.AspectModelResolver.resolveAspectModel(AspectModelResolver.java:133)

at org.eclipse.esmf.aspectmodel.resolver.AspectModelResolver.lambda$loadAndResolveModelFromDir$33570ba8$1(AspectModelResolver.java:414)

at io.vavr.control.Try$WithResources1.lambda$of$97fea75d$1(Try.java:1392)

at io.vavr.control.Try.of(Try.java:75)

at io.vavr.control.Try$WithResources1.of(Try.java:1390)

at org.eclipse.esmf.aspectmodel.resolver.AspectModelResolver.lambda$loadAndResolveModelFromDir$53c64c99$1(AspectModelResolver.java:414)

at io.vavr.control.Try.flatMapTry(Try.java:490)

at org.eclipse.esmf.aspectmodel.resolver.AspectModelResolver.loadAndResolveModelFromDir(AspectModelResolver.java:412)

at org.eclipse.esmf.aspectmodel.resolver.AspectModelResolver.lambda$loadAndResolveModel$9(AspectModelResolver.java:385)

at io.vavr.control.Try.orElse(Try.java:726)

at org.eclipse.esmf.aspectmodel.resolver.AspectModelResolver.loadAndResolveModel(AspectModelResolver.java:385)

at org.eclipse.esmf.AbstractCommand.loadAndResolveModel(AbstractCommand.java:53)

at org.eclipse.esmf.aspect.AspectValidateCommand.run(AspectValidateCommand.java:60)

at picocli.CommandLine.executeUserObject(CommandLine.java:2026)

at picocli.CommandLine.access$1500(CommandLine.java:148)

at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2461)

at picocli.CommandLine$RunLast.handle(CommandLine.java:2453)

at picocli.CommandLine$RunLast.handle(CommandLine.java:2415)

at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2273)

at picocli.CommandLine$RunLast.execute(CommandLine.java:2417)

at org.eclipse.esmf.LoggingMixin.executionStrategy(LoggingMixin.java:41)

at picocli.CommandLine.execute(CommandLine.java:2170)

at org.eclipse.esmf.SammCli.main(SammCli.java:106)

Caused by: java.io.FileNotFoundException: No model file containing urn:samm:io.catenax.shared.shopfloor_information_types:1.0.0#TimeValueCharacteristic could be found in directory: /Users/johannes/Documents/GitHub/sldt-semantic-models/io.catenax.shopfloor_information.provide_production_forecast/1.0.0/io.catenax.shared.shopfloor_information_types/1.0.0. AND No model file containing urn:samm:io.catenax.shared.shopfloor_information_types:1.0.0#TimeValueCharacteristic could be found in directory: /Users/johannes/Documents/GitHub/sldt-semantic-models/io.catenax.shopfloor_information.provide_production_forecast/1.0.0/io.catenax.shared.shopfloor_information_types/1.0.0

at org.eclipse.esmf.aspectmodel.resolver.FileSystemStrategy$DefaultNamespace.lambda$apply$0(FileSystemStrategy.java:137)

at io.vavr.API$Match$Case0.apply(API.java:5135)

at io.vavr.API$Match.option(API.java:5105)

at io.vavr.control.Try.mapFailure(Try.java:602)

at org.eclipse.esmf.aspectmodel.resolver.FileSystemStrategy$DefaultNamespace.lambda$apply$1(FileSystemStrategy.java:136)

at io.vavr.control.Try.recoverWith(Try.java:858)

at org.eclipse.esmf.aspectmodel.resolver.FileSystemStrategy$DefaultNamespace.apply(FileSystemStrategy.java:134)

at org.eclipse.esmf.aspectmodel.resolver.FileSystemStrategy$DefaultNamespace.apply(FileSystemStrategy.java:116)

at org.eclipse.esmf.aspectmodel.resolver.AspectModelResolver.getModelForUrn(AspectModelResolver.java:332)

at org.eclipse.esmf.aspectmodel.resolver.AspectModelResolver.resolve(AspectModelResolver.java:262)

As you can see it tries to find the linked file in

<...>/sldt-semantic-models/io.catenax.shopfloor_information.provide_production_forecast/1.0.0/io.catenax.shared.shopfloor_information_types/1.0.0

but it should be

<...>/sldt-semantic-models/io.catenax.shared.shopfloor_information_types/1.0.0

Where ESMF CLI 2.3.2

~/Downloads/samm-cli-2.3.2.jar aspect io.catenax.shopfloor_information.provide_production_forecast/1.0.0/ProvideProductionForecast.ttl validate
bs-jokri commented 1 year ago

Thanks to @RaMisess the problem was found in the model, which had a spelling mistake in the namespace. However, it might still be good if the resolver would produce a better error message so that the ordinary layperson would also spot the problem.