Prevent a crash that happens when config["harvester"]["plot_directories"] is not a list (#13551)

This commit is contained in:
Izumi Hoshino
2022-09-30 17:49:07 -05:00
committed by GitHub
parent 2fc65e1178
commit 42e67f049e
+3 -1
View File
@@ -69,7 +69,7 @@ class PlotRefreshResult:
def get_plot_directories(root_path: Path, config: Dict = None) -> List[str]:
if config is None:
config = load_config(root_path, "config.yaml")
return config["harvester"]["plot_directories"]
return config["harvester"]["plot_directories"] or []
def get_plot_filenames(root_path: Path) -> Dict[Path, List[Path]]:
@@ -93,6 +93,8 @@ def add_plot_directory(root_path: Path, str_path: str) -> Dict:
with lock_and_load_config(root_path, "config.yaml") as config:
if str(Path(str_path).resolve()) in get_plot_directories(root_path, config):
raise ValueError(f"Path already added: {path}")
if not config["harvester"]["plot_directories"]:
config["harvester"]["plot_directories"] = []
config["harvester"]["plot_directories"].append(str(Path(str_path).resolve()))
save_config(root_path, "config.yaml", config)
return config