def _verify_bore_connectivity(bore_connectivity, nBoreholes):
    """
    Verifies that borehole connectivity is valid.

    This function raises an error if the supplied borehole connectivity is
    invalid.

    Parameters
    ----------
    bore_connectivity : list
        Index of fluid inlet into each borehole. -1 corresponds to a borehole
        connected to the bore field inlet.
    nBoreholes : int
        Number of boreholes in the bore field.

    """
    if not len(bore_connectivity) == nBoreholes:
        raise ValueError(
            'The length of the borehole connectivity list does not correspond to the number of boreholes in the bore field.'
            )
    for i in range(nBoreholes):
        n = 0
        index_in = bore_connectivity[i]
        while not index_in == -1:
            index_in = bore_connectivity[index_in]
            n += 1
            if n > nBoreholes:
                raise ValueError('The borehole connectivity list is invalid.')
    return
