raise an error if item was using invalid preset.
This commit is contained in:
parent
ee2fd3f398
commit
4a21592e12
2 changed files with 19 additions and 0 deletions
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in a new issue