While testing different regex for THIS TOPIC, I created a flow to permit easy entry of strings and regex for validation in a Switch Node. This worked great until I put in an invalid regex. This caused an exception ("SyntaxError: Invalid regular expression") in the Switch Node and rendered It inoperable until doing a flow restart. The other nodes continued to process normally but the Switch Node no longer provided any output.
No problem, I thought. I will just add a catch-all and clear out the bad regex. Sadly, this does not work. Here are the exception details as written to debug by my handler:
EXCEPTION
PAYLOAD:^\d$\
TOPIC:
MESSAGE: SyntaxError: Invalid regular expression: /^\d$\/: \ at end of pattern
ID: b3061e66.00584
TYPE: switch
NAME: VALIDATE
COUNT: 1
Is this a recoverable error and, if so, how? Or is it maybe possible to restart an individual node or the whole flow from within the flow? This is not critical to my current development, just an inconvenience to what could be a useful tool. But it also has me thinking about other scenarios where exceptions might occur so thought I'd post here.
Here is my RegEx Tester flow:
[{"id":"a3cfa7e5.854208","type":"tab","label":"RegEx Tester","disabled":false,"info":""},{"id":"65ddf528.b9e03c","type":"ui_text_input","z":"a3cfa7e5.854208","name":"Get String","label":"Enter string","tooltip":"","group":"5eeb116e.bcdaa","order":2,"width":16,"height":1,"passthru":false,"mode":"text","delay":"500","topic":"topic","topicType":"msg","x":750,"y":360,"wires":[["81438305.7c07c"]]},{"id":"81438305.7c07c","type":"change","z":"a3cfa7e5.854208","name":"","rules":[{"t":"set","p":"string","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":960,"y":360,"wires":[["5b132ece.12048"]]},{"id":"dcda1e70.ab5a4","type":"ui_text_input","z":"a3cfa7e5.854208","name":"Get RegEx","label":"Enter regex","tooltip":"","group":"5eeb116e.bcdaa","order":3,"width":16,"height":1,"passthru":false,"mode":"text","delay":"500","topic":"topic","topicType":"msg","x":750,"y":320,"wires":[["447f2c34.88c044"]]},{"id":"447f2c34.88c044","type":"change","z":"a3cfa7e5.854208","name":"","rules":[{"t":"set","p":"regex","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":960,"y":320,"wires":[["5b132ece.12048"]]},{"id":"80e4de31.025b8","type":"ui_text","z":"a3cfa7e5.854208","group":"5eeb116e.bcdaa","order":4,"width":16,"height":1,"name":"Result","label":"{{msg.label}}","format":"{{msg.payload}}","layout":"col-center","x":1650,"y":340,"wires":[]},{"id":"b3061e66.00584","type":"switch","z":"a3cfa7e5.854208","name":"VALIDATE","property":"string","propertyType":"flow","rules":[{"t":"regex","v":"regex","vt":"flow","case":false},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1320,"y":340,"wires":[["c0d00ce6.19f86"],["fd75b71d.49c2c8"]],"outputLabels":["MATCH","NOT MATCH "]},{"id":"c0d00ce6.19f86","type":"change","z":"a3cfa7e5.854208","name":"MATCH","rules":[{"t":"set","p":"payload","pt":"msg","to":"MATCH","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1480,"y":320,"wires":[["80e4de31.025b8"]]},{"id":"fd75b71d.49c2c8","type":"change","z":"a3cfa7e5.854208","name":"NO MATCH","rules":[{"t":"set","p":"payload","pt":"msg","to":"NO MATCH","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1490,"y":360,"wires":[["80e4de31.025b8"]]},{"id":"5b132ece.12048","type":"change","z":"a3cfa7e5.854208","name":"","rules":[{"t":"set","p":"label","pt":"msg","to":"$flowContext('string') & '~=' & $flowContext('regex')","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1150,"y":340,"wires":[["b3061e66.00584"]]},{"id":"e29dc3ef.7f272","type":"change","z":"a3cfa7e5.854208","name":"CLEAR regex","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":760,"y":280,"wires":[["447f2c34.88c044"]]},{"id":"c7a610d6.435af","type":"comment","z":"a3cfa7e5.854208","name":"+++++++++++++++++++++++++ REGEX TESTER +++++++++++++++++++++++++","info":"","x":1090,"y":140,"wires":[]},{"id":"3510c421.20fa9c","type":"ui_text","z":"a3cfa7e5.854208","group":"5eeb116e.bcdaa","order":1,"width":0,"height":0,"name":"","label":"REGEX TESTER","format":"","layout":"row-center","x":1120,"y":200,"wires":[]},{"id":"f3b4e24b.e2042","type":"catch","z":"a3cfa7e5.854208","name":"Catch All Errors","scope":null,"uncaught":false,"x":340,"y":260,"wires":[["eeceb4b2.bbdfc8"]]},{"id":"eeceb4b2.bbdfc8","type":"change","z":"a3cfa7e5.854208","name":"Format Exception","rules":[{"t":"set","p":"payload","pt":"msg","to":"\"EXCEPTION\" & \t\"\\nPAYLOAD:\" & msg.payload & \t\"\\nTOPIC: \" & msg.topic &\t\"\\nMESSAGE: \" & msg.error.message &\t\"\\nID: \" & msg.error.source.id &\t\"\\nTYPE: \" & msg.error.source.type &\t\"\\nNAME: \" & msg.error.source.name &\t\"\\nCOUNT: \" & msg.error.source.count","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":260,"wires":[["17fec17b.26f6ff","e29dc3ef.7f272"]]},{"id":"17fec17b.26f6ff","type":"debug","z":"a3cfa7e5.854208","name":"EXCEPTION","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":240,"wires":[]},{"id":"5eeb116e.bcdaa","type":"ui_group","name":"RegEx Tester","tab":"3dc7d05e.02791","order":1,"disp":false,"width":16,"collapse":false},{"id":"3dc7d05e.02791","type":"ui_tab","name":"RegEx Tester","icon":"dashboard","order":14,"disabled":false,"hidden":false}]
If it matters, this is Node-RED v1.2.7 on Raspbian 10.8 on a Pi4 B1.2.
Thanks!
Peter