Skip to content

Commit f9776bc

Browse files
authored
Restore model validation not to fail on diagnostic errors for rules and scripts (#5351)
* Restore model validation not to fail on diagnostic errors Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
1 parent 50aea47 commit f9776bc

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

bundles/org.openhab.core.model.core/src/main/java/org/openhab/core/model/core/internal/ModelRepositoryImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,12 @@ private boolean validateModel(String name, InputStream inputStream, List<String>
331331

332332
// Check for validation errors, but log them only
333333
try {
334+
String modelType = resource.getURI().fileExtension();
334335
final org.eclipse.emf.common.util.Diagnostic diagnostic = safeEmf
335336
.call(() -> Diagnostician.INSTANCE.validate(resource.getContents().getFirst()));
336337
for (org.eclipse.emf.common.util.Diagnostic d : diagnostic.getChildren()) {
337-
if (d.getSeverity() == org.eclipse.emf.common.util.Diagnostic.ERROR) {
338+
if (d.getSeverity() == org.eclipse.emf.common.util.Diagnostic.ERROR
339+
&& !"rules".equalsIgnoreCase(modelType) && !"script".equalsIgnoreCase(modelType)) {
338340
errors.add(d.getMessage());
339341
} else {
340342
warnings.add(d.getMessage());

itests/org.openhab.core.model.rule.tests/src/main/java/org/openhab/core/model/rule/runtime/DSLRuleProviderTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,4 +268,26 @@ public void testVars() {
268268
Object x = context.getValue(QualifiedName.create("x"));
269269
assertThat(x, is(15));
270270
}
271+
272+
@Test
273+
public void testRuleWithUntypedLambdaArgsDoesNotFailToLoad() {
274+
Collection<Rule> rules = dslRuleProvider.getAll();
275+
assertThat(rules.size(), is(0));
276+
277+
String model = """
278+
var lambdaWithUntypedArgs = [ foo | foo ]
279+
rule "RuleWithUntypedLambdaArgs"
280+
when
281+
System started
282+
then
283+
logInfo('Test', 'Test')
284+
end
285+
""";
286+
287+
modelRepository.addOrRefreshModel(TESTMODEL_NAME,
288+
new ByteArrayInputStream(model.getBytes(StandardCharsets.UTF_8)));
289+
Collection<Rule> actualRules = dslRuleProvider.getAll();
290+
291+
assertThat(actualRules.size(), is(1));
292+
}
271293
}

0 commit comments

Comments
 (0)