import pathlib


def check_dir(path, name):
    """Check that a directory exists.

    Args:
        path (:obj:`pathlib.Path` or :obj:`str`):
            Path to check.
        name (:obj:`str`):
            Reference name of path.

    Raises:
        :exc:`Exception`:
            If path does not exist.

    Returns:
        :obj:`pathlib.Path`

    """
    path = pathlib.Path(path).expanduser().absolute()

    if not path.is_dir():
        error = "Unable to find {name!r} path '{path!r}'"
        error = error.format(path=format(path), name=name)
        raise Exception(error)
    return path