from typing import Counter


def oph_raise_for_duplicates(object_pairs):
    """Given an list of ordered pairs, contstruct a dict as with the
    normal JSON ``object_pairs_hook``, but raise an exception if there
    are duplicate keys with a message describing all violations.

    """

    counter = Counter(p[0] for p in object_pairs)
    duplicates = [p for p in iter(counter.items()) if p[1] > 1]

    if duplicates:
        raise ValueError(
            "The document contains duplicate keys: {}".format(
                ",".join(d[0] for d in duplicates)
            )
        )

    return {pair[0]: pair[1] for pair in object_pairs}