Restore model validation not to fail on diagnostic errors for rules and scripts - #5351
Conversation
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
|
This pull request has been mentioned on openHAB Community. There might be relevant details there: |
|
We should restore only for DSL rules and not for other DSL stuff. If not, you will break what you have done |
Do you happen to remember why we had to be strict? At the very least, if we do need to be strict, we need to add a test that would fail when it isn't (like when it's changed in this PR) |
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
|
Before #4928
We thought that being strict was a good thing, but it may not be. This PR restores the error "tolerance" that we used to have pre-5.1. Syntax errors still cause the whole file to be rejected. The only other thing we should probably change is the logging should not be info. It should be a warning - wdyt? |
These errors come from https://github.com/eclipse-xtext/xtext/blob/main/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/validation/XbaseValidator.java, which contains:
One approach is to create a class, which derives from XbaseValidator, which overwrites some methods, by replacing // contributed by org.eclipse.xtext.xtext.generator.validation.ValidatorFragment2
@SingletonBinding(eager=true)
public Class<? extends XbaseValidator> bindXbaseValidator() {
return NewXbaseValidator.class;
}Another approach is to ask upstream to change these errors into warnings. Xbase — which is used by DSL Rules/Scripts/Transformations — has two modes of evaluation: Interpeted mode, which openHAB uses, and g.members.forEach[ u | logError(“A”, u.name + “|” + u.state + " | " + u.class.toString) ]produces in interpeter mode the message
and after parsing it is interpreted at runtime correctly, in the other mode, when generating So if some input produces at parsing data, which cannot be converted immediately to Or, third variant, find out how to turn all validation/parsing errors into warnings only for the Rules/Scripts/Transformations model. But this might not work, e.g. these errors:
are errors and not warnings. |
|
If code is not going to change, then this could be added as “Breaking Change” under - https://github.com/openhab/openhab-distro/releases/tag/5.1.0#breaking-changes-that-require-manual-interaction-after-the-upgrade - XBase errors are not anymore converted to warnings. |
Yes, there was a very good reason even if I don't yet remember exactly which one. It was to not load a wrong item. Edit: we can check where error is used in validation checks to remember the reason. |
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
|
@lolodomo I've just pushed a commit that restores the errors/warnings but makes an exception for rules and scripts. If we want to make rules/scripts stricter again in the future, we should do so in a separate PR. |
| } | ||
| if (!newWarnings.isEmpty()) { | ||
| logger.info("Validation issues found in DSL model '{}', using it anyway:\n{}", name, | ||
| logger.warn("Validation issues found in DSL model '{}', using it anyway:\n{}", name, |
There was a problem hiding this comment.
Can you please keep the original log level.
We have a different log level for errors leading to model not being loaded and model being loaded but with warnings/tips.
With your change, everything will be a WARNING. And that would made the approach different from what was also done for YAML files.
| if (d.getSeverity() == org.eclipse.emf.common.util.Diagnostic.ERROR | ||
| && !"rules".equals(modelType) && !"script".equals(modelType)) { |
There was a problem hiding this comment.
That is the fix I have in mind.
For consistency with the other places in that file, I would rather suggest:
!"rules".equalsIgnoreCase(resource.getURI().fileExtension()) &&
!"script".equalsIgnoreCase(resource.getURI().fileExtension())
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
|
It looks good to me now. Thank you Jim. |
|
Maybe you could add "for rules and scripts" in the PR title. |
|
Thanks for your help @lolodomo! @dilyanpalauzov thanks for the background in xbase / xtend. Do you think going forward we should enforce stricter validations for rulesdsl or should we just leave it as is? |
…nd scripts (#5351) * Restore model validation not to fail on diagnostic errors Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
|
Cherry-picked it to |
I am not sure. As it was and is also now, more relaxed checking (errors are warnings) just works most of the time. But sometimes it prevents errors to pop-up during parsing, and I do not know what happens, if these errors happen at run-time. |
|
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/rules-and-rule-templates-yaml-integration/168568/194 |
|
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/dsl-error-when-comparing-two-string-variables/169756/15 |
Fixes a regression introduced in #4928
Problem reported in https://community.openhab.org/t/rules-dsl-in-5-1-is-now-unloading-rules-if-it-has-unreachable-expressions/168382