Not sure, but try to change first line :
to this :
With this change, you'll be able to apply sub function only to those INSERT entities that in essence have ATTRIB (s) attached - basically it'll automatically filter out XREF and all other INSERT (weather they are "dynamic" or "classic") that don't have ATTRIB (s) attached...
I can only guess - you probably applied sub to those that don't have DXF '(66 . 1) - XREF or INSERT [ without ATTRIB (s) ] which is perhaps why CAD rised an error [ assuming that you previously didn't have any issues regarding this sub ]...
I don't believe that very much changed in newer BricsCAD V22 in relation to AutoLISP and so on... Good thing is that you can see throwing error(s), though IMHO, VLIDE (AutoCAD) is much better for debugging purposes than BLADE (BricsCAD)...