From dcb4bdfb9b5471e0fa347dc062f9e252c0ac8cbf Mon Sep 17 00:00:00 2001 From: Barry Downes Date: Sat, 5 Aug 2023 16:18:52 +1000 Subject: [PATCH] Move ParseLogicError into comfy.parse. Don't catch ParseError in comfy.choices. --- comfy/choices.py | 21 +++++---------------- comfy/parse.py | 6 ++++++ 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/comfy/choices.py b/comfy/choices.py index 8aed198d6..2833b246e 100644 --- a/comfy/choices.py +++ b/comfy/choices.py @@ -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 diff --git a/comfy/parse.py b/comfy/parse.py index 9ac3e2544..df0bbc371 100644 --- a/comfy/parse.py +++ b/comfy/parse.py @@ -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+'):