From 1d3672f6466719489b1509c6f286466e6ff5cafa Mon Sep 17 00:00:00 2001 From: Burt Holzman Date: Mon, 11 Mar 2024 16:22:28 +0000 Subject: [PATCH 1/3] Ignore pageconfig file if JSON is invalid --- jupyterlab_server/config.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/jupyterlab_server/config.py b/jupyterlab_server/config.py index 93c4abc..7f47c1f 100644 --- a/jupyterlab_server/config.py +++ b/jupyterlab_server/config.py @@ -127,14 +127,17 @@ def get_page_config( ] for path in config_paths: if osp.exists(path): - data = load_config(path) - # Convert lists to dicts - for key in [disabled_key, "deferredExtensions"]: - if key in data: - data[key] = {key: True for key in data[key]} - - recursive_update(page_config, data) - break + try: + data = load_config(path) + # Convert lists to dicts + for key in [disabled_key, "deferredExtensions"]: + if key in data: + data[key] = {key: True for key in data[key]} + + recursive_update(page_config, data) + break + except json.decoder.JSONDecodeError: + logger.warning("%s is not valid JSON", path) # Get the traitlets config static_page_config = get_static_page_config(logger=logger, level="all") From 9debc1a51f3d6ffb593cb37f4098eed2f7e16f7e Mon Sep 17 00:00:00 2001 From: Burt Holzman Date: Mon, 11 Mar 2024 21:47:41 +0000 Subject: [PATCH 2/3] Check for optional logger before using it --- jupyterlab_server/config.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/jupyterlab_server/config.py b/jupyterlab_server/config.py index 7f47c1f..5369357 100644 --- a/jupyterlab_server/config.py +++ b/jupyterlab_server/config.py @@ -137,7 +137,8 @@ def get_page_config( recursive_update(page_config, data) break except json.decoder.JSONDecodeError: - logger.warning("%s is not valid JSON", path) + if logger: + logger.warning("%s is not valid JSON", path) # Get the traitlets config static_page_config = get_static_page_config(logger=logger, level="all") From 7f340640871348bb73293c30244c2ecc97cad7de Mon Sep 17 00:00:00 2001 From: Burt Holzman Date: Wed, 13 Mar 2024 15:37:05 +0000 Subject: [PATCH 3/3] Ignore pageconfig only if it is zero length --- jupyterlab_server/config.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/jupyterlab_server/config.py b/jupyterlab_server/config.py index 5369357..9f80b35 100644 --- a/jupyterlab_server/config.py +++ b/jupyterlab_server/config.py @@ -126,19 +126,15 @@ def get_page_config( pjoin(app_settings_dir, "page_config.json"), ] for path in config_paths: - if osp.exists(path): - try: - data = load_config(path) - # Convert lists to dicts - for key in [disabled_key, "deferredExtensions"]: - if key in data: - data[key] = {key: True for key in data[key]} - - recursive_update(page_config, data) - break - except json.decoder.JSONDecodeError: - if logger: - logger.warning("%s is not valid JSON", path) + if osp.exists(path) and osp.getsize(path): + data = load_config(path) + # Convert lists to dicts + for key in [disabled_key, "deferredExtensions"]: + if key in data: + data[key] = {key: True for key in data[key]} + + recursive_update(page_config, data) + break # Get the traitlets config static_page_config = get_static_page_config(logger=logger, level="all")