Commit b594f518 authored by AUTOMATIC1111's avatar AUTOMATIC1111 Committed by GitHub

Merge pull request #14814 from AUTOMATIC1111/catch-load-style.csv-error

catch load style.csv error
parents 652a7bbf bbe8e02d
from pathlib import Path from pathlib import Path
from modules import errors
import csv import csv
import os import os
import typing import typing
...@@ -128,6 +129,7 @@ class StyleDatabase: ...@@ -128,6 +129,7 @@ class StyleDatabase:
self.load_from_csv(styles_file) self.load_from_csv(styles_file)
def load_from_csv(self, path: str | Path): def load_from_csv(self, path: str | Path):
try:
with open(path, "r", encoding="utf-8-sig", newline="") as file: with open(path, "r", encoding="utf-8-sig", newline="") as file:
reader = csv.DictReader(file, skipinitialspace=True) reader = csv.DictReader(file, skipinitialspace=True)
for row in reader: for row in reader:
...@@ -141,6 +143,8 @@ class StyleDatabase: ...@@ -141,6 +143,8 @@ class StyleDatabase:
self.styles[row["name"]] = PromptStyle( self.styles[row["name"]] = PromptStyle(
row["name"], prompt, negative_prompt, str(path) row["name"], prompt, negative_prompt, str(path)
) )
except Exception:
errors.report(f'Error loading styles from {path}: ', exc_info=True)
def get_style_paths(self) -> set: def get_style_paths(self) -> set:
"""Returns a set of all distinct paths of files that styles are loaded from.""" """Returns a set of all distinct paths of files that styles are loaded from."""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment