The documentation of the function posn-at-point states "Return nil if position is not visible in window.", but it may also signal an error in this case. This happens, if Fpos_visible_in_window_p returns a list of (X Y RTOP RBOT ROWH VPOS) and at least Y is negative (which indicates, that pos is not visible IIUC). The error is then signaled by Fposn_at_x_y, which only accpets non-negative numbers (neglecting the exceptional case of -1 for X). I think this function should include a similar test for y, as is already in place for x, returning nil if it is negative (see below).