handle config.json failed to load

This commit is contained in:
w-e-w 2024-01-04 06:21:53 +09:00
parent 04a005f0e9
commit 50158a1fc9
2 changed files with 12 additions and 4 deletions

View File

@ -249,7 +249,9 @@ def list_extensions(settings_file):
with open(settings_file, "r", encoding="utf8") as file: with open(settings_file, "r", encoding="utf8") as file:
settings = json.load(file) settings = json.load(file)
except Exception: except Exception:
errors.report("Could not load settings", exc_info=True) errors.report(f'\nCould not load settings\nThe config file "{settings_file}" is likely corrupted\nIt has been moved to the "tmp/config.json"\nReverting config to default\n\n''', exc_info=True)
os.replace(settings_file, os.path.join(script_path, "tmp", "config.json"))
settings = {}
disabled_extensions = set(settings.get('disabled_extensions', [])) disabled_extensions = set(settings.get('disabled_extensions', []))
disable_all_extensions = settings.get('disable_all_extensions', 'none') disable_all_extensions = settings.get('disable_all_extensions', 'none')

View File

@ -1,3 +1,4 @@
import os
import json import json
import sys import sys
from dataclasses import dataclass from dataclasses import dataclass
@ -6,6 +7,7 @@ import gradio as gr
from modules import errors from modules import errors
from modules.shared_cmd_options import cmd_opts from modules.shared_cmd_options import cmd_opts
from modules.paths_internal import script_path
class OptionInfo: class OptionInfo:
@ -193,9 +195,13 @@ class Options:
return type_x == type_y return type_x == type_y
def load(self, filename): def load(self, filename):
try:
with open(filename, "r", encoding="utf8") as file: with open(filename, "r", encoding="utf8") as file:
self.data = json.load(file) self.data = json.load(file)
except Exception:
errors.report(f'\nCould not load settings\nThe config file "{filename}" is likely corrupted\nIt has been moved to the "tmp/config.json"\nReverting config to default\n\n''', exc_info=True)
os.replace(filename, os.path.join(script_path, "tmp", "config.json"))
self.data = {}
# 1.6.0 VAE defaults # 1.6.0 VAE defaults
if self.data.get('sd_vae_as_default') is not None and self.data.get('sd_vae_overrides_per_model_preferences') is None: if self.data.get('sd_vae_as_default') is not None and self.data.get('sd_vae_overrides_per_model_preferences') is None:
self.data['sd_vae_overrides_per_model_preferences'] = not self.data.get('sd_vae_as_default') self.data['sd_vae_overrides_per_model_preferences'] = not self.data.get('sd_vae_as_default')