Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle config.json failed to load #14525

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion modules/launch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,9 @@ def list_extensions(settings_file):
with open(settings_file, "r", encoding="utf8") as file:
settings = json.load(file)
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', []))
disable_all_extensions = settings.get('disable_all_extensions', 'none')
Expand Down
12 changes: 9 additions & 3 deletions modules/options.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import json
import sys
from dataclasses import dataclass
Expand All @@ -6,6 +7,7 @@

from modules import errors
from modules.shared_cmd_options import cmd_opts
from modules.paths_internal import script_path


class OptionInfo:
Expand Down Expand Up @@ -193,9 +195,13 @@ def same_type(self, x, y):
return type_x == type_y

def load(self, filename):
with open(filename, "r", encoding="utf8") as file:
self.data = json.load(file)

try:
with open(filename, "r", encoding="utf8") as 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
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')
Expand Down