models: be even more defensive when parsing input

also we finally read the documentation for str.find()
https://docs.python.org/3/library/stdtypes.html#str.find
This commit is contained in:
bronsen 2026-02-19 20:42:50 +01:00
parent 0ae116afa9
commit 49a21ca9cf

View file

@ -37,12 +37,20 @@ async def make_teilchen_input(text: str) -> TeilchenCreate | None:
import re
from natsort import natsorted
text = text.strip()
if not text:
logger.error("Empty text.")
return None
name_end = text.find(".")
if name_end == -1: # "." not in text
logger.warning("Missing period '.' from text.")
logger.debug("Could not find period symbol in input: %s", text)
return None
else:
name = text[0:name_end]
if not name:
logger.error("Could not extract name.")
logger.debug("Could not extract name from input: %s", text)