invalid internal item number

With this script I have the same error: “invalid internal item number”. It works on a hAP ac^2 and does not work on a RB4011. Both with v7.11.2.


:local output
:local filename
:local sysname  [/system identity get name]

:set filename  ($"sysname"."-"."Leases.txt")

/ip dhcp-server lease
:foreach i in=[find] do={
    :local hname      [get $i host-name]
    :local activeMAC  [get $i active-mac-address]
    :local Address    [get $i address]
    :local macAddress [get $i mac-address]
    :local Status     [get $i status]
    :local Comment    [get $i comment]
    :local iface      "undefined"
    
    /interface bridge host
    :local searchresult [find where mac-address=$activeMAC]
    :if ([:len $searchresult] > 0) do={
        :set iface [get $searchresult on-interface]
    
        :if (([:typeof $hname] = "nil") && ($Status = "bound")) do={
            :set output ($output . ($Address . "\t" . $macAddress . "\t" . $Status . "\t" . $iface . "\t" . $Comment) . "\n")
        } 
        :if (([:typeof $hname] != "nil") && ($Status = "bound")) do={
            :set output ($output . ($Address . "\t" . $macAddress . "\t" . $Status . "\t" . $iface . "\t" . $hname) . "\n")
        }
    }
}

/file print file=$filename
:delay 2s
/file set $filename contents=$output

EDIT: I don’t understand anything, but there was a host in the DHCP Lease list that made it give that error, after disabling it it is working again. I am sorry for this.