def _construct_ambiguous_deletion_message(username, hostname, matches):
    """Create an error message for an ambiguous request to delete a credential.

    This function should only be used by `delete_credential`.

    Args:
        username: The username for the credential targeted for deletion.
        hostname: The hostname for the credential targeted for deletion, if any.
        matches: the collection of possibly matching credentials found by delete_credential.

    Returns:
        An error message string.

    """
    err = f"Ambiguous credentials found for username '{username}'"
    if hostname is not None:
        err += f" with hostname '{hostname}'\n"
    else:
        err += " with no hostname specified\n"
    err += "Matched credentials:"
    for match in matches:
        err += f"\n  {match.username}"
        if len(match.hostname) == 0:
            err += " which has no associated hostname"
        else:
            err += f" for {match.hostname}"
    return err