script.model.ScriptInterpreter: emit what cannot be casted to what after a single evaluation of the cast#5329
Conversation
|
When I run locally
it completes without problems. I do not understand the errors on https://github.com/openhab/openhab-core/actions/runs/21747525180/job/62737006376?pr=5329: |
|
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/issues-with-datetimetype-cast/162281/6 |
9d74199 to
f9069c0
Compare
after a single evaluation of the cast. Before this change
internalEvaluate(castedExpression.getTarget(), context, indicator)
was invoked twice. When on the first execution an error occured, the
second execution was needed to create an error message, stating what
cannot be casted to what. However at the time internalEvaluate was
called for a second time, internal states have changed, so there might
be no more errors with casting, thus producing incorrect error message.
Except the line
"Could not cast (" + result.class + ")" + result + " to " + typeName
the implementation is the same as in XbaseInterpreter.java.
f9069c0 to
2d20983
Compare
|
The other change is switching from throw new ScriptExecutionException(new ScriptError(to throw new EvaluationException(new ClassCastException(It allows catching ClassCastException within the DSL Script/Rule/Transformation, instead of aborting the XBase interpreter. First ExampleFor an item does:
Second ExampleFor an item does:
The difference is that before the change the line and column numbers were printed. |
|
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/major-problems-in-rules-execution-since-openhab5/168397/4 |
Before this change
internalEvaluate(castedExpression.getTarget(), context, indicator)was invoked twice: once bysuper._doEvaluate()and once in the overridden method. When on the first execution an error occured, the second execution was needed to create an error message, stating what cannot be casted to what. However at the timeinternalEvaluatewas called for a second time, internal states have changed, so there might be no more errors with casting, thus producing incorrect error message.Except the line:
OLD:
EDIT: the above change was changed, now the only difference is this line
the implementation is the same as in XbaseInterpreter.java, bur rewtiten in Xtend.
The problem has to be addressed in XBase, as it does not provide enough information about what cannot be casted to what — eclipse-xtext/xtext#3595.
I geuess that
@Inject CommonTypeComputationServices servicesis right. I do not understand it, but thesuper._doEvaluate(XCastedExpression, IEvaluationContext, CancelIndicator)method usesservicesin the same way.Closes #5323.
The error messages in the original report contained a string with a date value inside, and it was unclear if the object was a DateTimeType, a StringType or a String object.
The error messages are generated now as:
making clear not only the value, which cannot be casted, but also its class.