mwouts / jupytext

Jupyter Notebooks as Markdown Documents, Julia, Python or R scripts
https://jupytext.readthedocs.io
MIT License
6.65k stars 386 forks source link

invalid `pyproject.toml` breaks JupyterLab #1103

Closed edublancas closed 1 year ago

edublancas commented 1 year ago

Hi. Thanks a lot for jupytext, I've been an avid user for years!

I was testing some functionality we're adding to JupySQL and started to play around with invalid configurations:

[tool.jupysql.SqlMagic]
autopandas = False
displaylimit = 1

I put False on purpose to create an invalid TOML.

Then, I noticed my JupyterLab started giving errors, and the console showed this message:

    ValueError: Only all lowercase booleans allowed

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/Users/eduardo/miniconda3/envs/jupysql/lib/python3.10/site-packages/tornado/web.py", line 1786, in _execute
        result = await result
      File "/Users/eduardo/miniconda3/envs/jupysql/lib/python3.10/site-packages/jupyter_server/services/contents/handlers.py", line 122, in get
        self.contents_manager.get(
      File "/Users/eduardo/miniconda3/envs/jupysql/lib/python3.10/site-packages/jupytext/contentsmanager.py", line 199, in get
        return self.super.get(path, content, type, format)
      File "/Users/eduardo/miniconda3/envs/jupysql/lib/python3.10/site-packages/jupyter_server/services/contents/filemanager.py", line 428, in get
        model = self._dir_model(path, content=content)
      File "/Users/eduardo/miniconda3/envs/jupysql/lib/python3.10/site-packages/jupyter_server/services/contents/filemanager.py", line 320, in _dir_model
        contents.append(self.get(path=f"{path}/{name}", content=False))
      File "/Users/eduardo/miniconda3/envs/jupysql/lib/python3.10/site-packages/jupytext/contentsmanager.py", line 201, in get
        config = self.get_config(path, use_cache=content is False)
      File "/Users/eduardo/miniconda3/envs/jupysql/lib/python3.10/site-packages/jupytext/contentsmanager.py", line 571, in get_config
        config_file = self.get_config_file(parent_dir)
      File "/Users/eduardo/miniconda3/envs/jupysql/lib/python3.10/site-packages/jupytext/contentsmanager.py", line 518, in get_config_file
        doc = toml.loads(model["content"])
      File "/Users/eduardo/miniconda3/envs/jupysql/lib/python3.10/site-packages/toml/decoder.py", line 514, in loads
        raise TomlDecodeError(str(err), original, pos)
    toml.decoder.TomlDecodeError: Only all lowercase booleans allowed (line 2 column 1 char 24)

Since this is affecting the contents manager, this breaks JupyterLab, as files are no longer visible:

image

Uninstalling jupytext fixes the problem.

I'm using jupytext 1.14.7

mwouts commented 1 year ago

Hey @edublancas , thank you for your kinds words. Yes it would make sense to catch errors on invalid configurations, at least in Jupyter - I'll try to provide a fix soon.