[SOLVED] Error - Return in rulle?

In my rule I have something like this

if(alarmStatus!=ALARM_DEACTIVATED) {
			logInfo( "FILE", "Intruder_alarm: == END ==")
			return
		}

and when it is executed I get following error:

2017-12-16 23:35:19.376 [INFO ] [.eclipse.smarthome.model.script.FILE] - Intruder_alarm: =================== END ================================
2017-12-16 23:35:19.378 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'Intruder_alarm': An error occurred during the script execution: Unhandled parameter types: [null, org.eclipse.xtext.xbase.interpreter.impl.DefaultEvaluationContext@88d1e, org.eclipse.xtext.util.CancelIndicator$1@18f8014]

It is not a problem because rule is executed but this error appears in log.

Michal Szymanski

Don’t think your post has all the info needed. The code you posted looks OK, however, it is unclear how you have defined alarmStatus and ALARM_DEACTIVATED
Does the rule contain more statements, maybe it is connected to another line.
What can help quite a bit is adding more loginfo statements to make sure that all items, variables, etc contain the value that you expect them.
For items you can convert the state into string like so: MyItem.state.toString

You have already created a topic about this same question how to use return in rules. Why didn’t you continue there?
Can I use ‘return’ in rules?

As it is stated in the docs (Link is in your older post):

Caveat: Please note the semicolon after the return statement which terminates the command without an additional argument.

2 Likes

You are right I’ve forget about this topic :slight_smile:

Michal

It is not related with other parts of code and variable definition - it worked before adding return. But as was commented by gitMiguel there was a problem with semicolon.

Michal

1 Like

I suggest to mark your topics solved if somebody provides a solution and you get it working. Afterwards when other users are searching through the forum and trying to find answers it’s easier to pick the ones that has been already solved.

I’ve made a test once again and error happens even when I use “return;”.
When I remove return there is no exception :frowning:

            ..............
	if(alarmStatus!=ALARM_DEACTIVATED) {
		logInfo( "FILE", "Intruder_alarm: =================== END1 ================================")
		return
	}
	
	// sprawdzenie w jakim trybie jest wlaczony alarm
	if (AlarmMode==ALARM_MODE_ALL) {
           ..............

I’ve found few minutes ago Exit rule with return false the same problem

Does your rule require the return statement? Or does the rule work even when you have it in place? Can you post your whole rule so we can see if it’s possible to write it without return statement.

Rule is quite long and makes many thing that are not important when we talk about this bug but I’ve changed to “return;” to “return false” and now there is no error. From Exit rule with return false I know that “return;” was introduced but it is available in RC not in stable version. So far “return false” is ok for me.

Michal

1 Like