mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-06-23 00:09:32 +08:00
Move ParseLogicError into comfy.parse.
Don't catch ParseError in comfy.choices.
This commit is contained in:
parent
5a673ee930
commit
dcb4bdfb9b
@ -3,14 +3,8 @@
|
|||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
|
|
||||||
import comfy.parse
|
import comfy.parse as parse
|
||||||
from comfy.parse import ParseError
|
from comfy.parse import ParseError, ParseLogicError
|
||||||
|
|
||||||
class ParseLogicError(ParseError):
|
|
||||||
# something that shouldn't be possible occurred in the code
|
|
||||||
# not the user's fault
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def get_random_seed():
|
def get_random_seed():
|
||||||
return int.from_bytes(os.urandom(8))
|
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
|
# init our local random number generator
|
||||||
rng = random.Random(seed)
|
rng = random.Random(seed)
|
||||||
|
|
||||||
try:
|
input = parse.Cursor(text)
|
||||||
input = comfy.parse.Cursor(text)
|
out = parse_text_with_choices_outer(input)
|
||||||
out = parse_text_with_choices_outer(input)
|
return out
|
||||||
return out
|
|
||||||
except (ParseError) as e:
|
|
||||||
# alternative: re-throw the error
|
|
||||||
stdout.write(f'Error parsing prompt: {e}');
|
|
||||||
return text
|
|
||||||
|
|
||||||
|
|||||||
@ -10,6 +10,12 @@ class ParseError(Exception):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f'{self.message} {self.input.loc()}'
|
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:
|
class Cursor:
|
||||||
def __init__(self, text, skip_space=False, consume=True, space=r'\s+'):
|
def __init__(self, text, skip_space=False, consume=True, space=r'\s+'):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user