import bisect


def read_message(cask, channel, acqtime):
    """
        Retrieves a message by acqtime. Raises ValueError, if the message was not found.

        Arguments:
            cask (isaac.Cask): opened log file
            channel (str): Cask channel name
            acqtime (int): Target message acquisition time
    """

    class BisectHelper(object):
        def __init__(self, series):
            self.series = series
        def __len__(self):
            return len(self.series)
        def __getitem__(self, message_index):
            return self.series[message_index][0]

    cask_channel = cask[channel]
    message_index = bisect.bisect_left(BisectHelper(cask_channel.metadata), acqtime)
    if message_index == len(cask_channel) or cask_channel[message_index].acqtime != acqtime:
        raise ValueError
    return cask_channel[message_index]