Watch out for Blockly Fragments when you replace blocks

I am really enjoying Blockly in Rules. I have been slowly converting my Rules files, most of which I created in OpenHAB 2.x when I was first learning. I’m currently using OpenHAB 3.3M1 on a Pi4B running openhabian, but I doubt the platform matters in this case.

I have on more than on occasion had a rule fail that looked like it should work:


2022-03-28 21:46:05.551 [ERROR] [e.automation.internal.RuleEngineImpl] - Failed to execute rule 'KathleenPresenceConflictTimerStart': Fail to execute action: 3

By moving the Blockly elements around, I stumbled across some Blockly fragments that had slipped behind the main block. I think this happens when I attach a new block where there was already one. It makes sense that it doesn’t just delete the replaced information. But it would be better if it moved if clearly away from the other blocks. (I don’t doubt that the primary problem is that I’m still learning, but I suspect others will get surprised by this, so I’m sharing my experience.).

Though it is an older thread, I wanted to confirm that this is standard blockly behaviour. When you replace an already existing block it indeed keeps the old one (detached) and sometimes it gets hidden behind other blocks. This can be an issue in particular when you have bigger section of blocks.

As it is standard blockly behaviour it is hard to change. There are discussions to automatically disable non connected blocks but that has a number of side effect you don’t want to have either.

The only recommendation is to keep an eye on blocks that are being replaced or in case you have a strange behaviour, check for orphaned blocks in the background (I sometimes also take a quick look at the generated code to search for unexpected lines though this is more for advanced users).

Thanks. It is hard because the blocks can easily get lost. I have round it is worse on my iPad than on my laptop, but that may just be me. A warning that you have an orphaned block would be very user friendly.

I agree with your recommendation to review the code. Even though I don’t know the language, I found at least one orphaned block for a rule that wasn’t working by observing something extraneous in the code.