import click


def ensure_valid_type(node_type_choices: click.Choice, node_type: str) -> str:
    """Uses click's convert_type function to check the validity of the
    specified node_type. Re-raises with a custom error message to ensure
    consistency across click versions.
    """
    try:
        click.types.convert_type(node_type_choices)(node_type)
    except click.BadParameter:
        raise click.exceptions.UsageError(
            f"'{node_type}' is not one of {', '.join(map(repr, node_type_choices.choices))}."
        ) from None
    return node_type