Type error when executing calc

I’m getting a “type error: cannot convert null to an object” which I can’t resolve. The calc is of text type. Here’s the code:

if ( peoid$cor_to_peo.peo_com_id )
{
	if ( !peoid$cor_to_peo.first_name && !peoid$cor_to_peo.last_name && !peoid$cor_to_peo.full_name )
	{
		var name = peoid$cor_to_peo.job_func + i18n.getI18NMessage('7office.lbl.cr.of') + comid$cor_to_com.company_name;		
	}
	else
	{
		var name = peoid$cor_to_peo.first_last_name + i18n.getI18NMessage('7office.lbl.cr.of') + comid$cor_to_com.company_name;
	}
}
else
{
	var name = peoid$cor_to_peo.first_last_name;
}

if ( name )
{
	return i18n.getI18NMessage('7office.lbl.cor.correspondenceto') + name;
}
else
{
	return '';
}

The calc itself seems to be working fine. It returns and displays properly the expected text. Nevertheless I’m getting the yellow warning triangle.

Anyone spot what I’m missing?

You should make sure that the relation peoid$cor_to_peo is valid. What happens if you add for examle a

if (!utils.hasRecords(peoid$cor_to_peo))
{
   return '';
}

on top of the whole story? You should also make sure, that comid$cor_to_com is valid…