def nb_kernel_name(nb, name=None):
    """Helper for fetching out the kernel name from a notebook object.

    Parameters
    ----------
    nb : nbformat.NotebookNode
        The notebook to introspect
    name : str
        A provided name field

    Returns
    -------
    str
        The name of the kernel

    Raises
    ------
    ValueError
        If no kernel name is found or provided
    """
    name = name or nb.metadata.get('kernelspec', {}).get('name')
    if not name:
        raise ValueError("No kernel name found in notebook and no override provided.")
    return name