Move ParseLogicError into comfy.parse.

Don't catch ParseError in comfy.choices.
This commit is contained in:
Barry Downes 2023-08-05 16:18:52 +10:00
parent 5a673ee930
commit dcb4bdfb9b
2 changed files with 11 additions and 16 deletions

View File

@ -3,14 +3,8 @@
import os
import random
import comfy.parse
from comfy.parse import ParseError
class ParseLogicError(ParseError):
# something that shouldn't be possible occurred in the code
# not the user's fault
pass
import comfy.parse as parse
from comfy.parse import ParseError, ParseLogicError
def get_random_seed():
return int.from_bytes(os.urandom(8))
@ -133,12 +127,7 @@ def translate(text, seed=None, strict=True, reescape=frozenset()):
# init our local random number generator
rng = random.Random(seed)
try:
input = comfy.parse.Cursor(text)
out = parse_text_with_choices_outer(input)
return out
except (ParseError) as e:
# alternative: re-throw the error
stdout.write(f'Error parsing prompt: {e}');
return text
input = parse.Cursor(text)
out = parse_text_with_choices_outer(input)
return out

View File

@ -10,6 +10,12 @@ class ParseError(Exception):
def __str__(self):
return f'{self.message} {self.input.loc()}'
class ParseLogicError(ParseError):
# like a ParseError, in that it has an associated cursor position which will help in understanding the error
# but unlike a ParseError, because it wasn't the user's fault
# something that shouldn't be possible occurred in the code
pass
class Cursor:
def __init__(self, text, skip_space=False, consume=True, space=r'\s+'):