i think there are 2 errors. one is "while executing "X509::subject $cert" which can be avoid by checking SSL::cert count.
the other one is "while executing session lookup ssl [SSL::sessionid]" which i understand SSL::sessionid returns null. in this case, you may also have to check if SSL::sessionid is null before preceeding.
SSL::sessionid
Returns the current connection's SSL session ID if it exists in the session cache.
In version 10.x and higher, if the session ID does not exist in the cache, returns a null string.
SSL::sessionid wiki
https://devcentral.f5.com/wiki/irules.ssl__sessionid.ashx