raise an error if item was using invalid preset.

This commit is contained in:
arabcoders 2025-04-10 00:59:52 +03:00
parent ee2fd3f398
commit 4a21592e12
2 changed files with 19 additions and 0 deletions

View file

@ -134,6 +134,12 @@ class Item:
preset = item.get("preset")
if preset and isinstance(preset, str) and preset != Item._default_preset():
from .Presets import Presets
if not Presets.get_instance().has(preset):
msg = f"Preset '{preset}' does not exist."
raise ValueError(msg)
data["preset"] = preset
if item.get("folder") and isinstance(item.get("folder"), str):

View file

@ -266,6 +266,19 @@ class Presets(metaclass=Singleton):
return self
def has(self, id_or_name: str) -> bool:
"""
Check if the preset exists by id or name.
Args:
id_or_name (str): The id or name of the preset.
Returns:
bool: True if the preset exists, False otherwise.
"""
return self.get(id_or_name) is not None
def get(self, id_or_name: str) -> Preset | None:
"""
Get the preset by id or name.