Skip to content

Commit e92f134

Browse files
committed
Better error message for enum failures
1 parent 7dcd08d commit e92f134

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

mysql_ch_replicator/enum/parser.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def _extract_parenthesized_content(s, start_index):
4747
(Backticks do not process backslash escapes.)
4848
"""
4949
if s[start_index] != '(':
50-
raise ValueError("Expected '(' at position {}".format(start_index))
50+
raise ValueError("Expected '(' at position {} in: {!r}".format(start_index, s))
5151
depth = 1
5252
i = start_index + 1
5353
content_start = i
@@ -99,7 +99,14 @@ def _extract_parenthesized_content(s, start_index):
9999
else:
100100
i += 1
101101

102-
raise ValueError("Unbalanced parentheses in enum definition")
102+
# Enhanced error message with actual input
103+
raise ValueError(
104+
f"Unbalanced parentheses in enum definition. "
105+
f"Input: {s!r}, "
106+
f"Started at index {start_index}, "
107+
f"Depth at end: {depth}, "
108+
f"Still in quote: {in_quote!r}"
109+
)
103110

104111

105112
def _parse_enum_values(content):

mysql_ch_replicator/enum/utils.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def find_enum_definition_end(text: str, start_pos: int) -> int:
1717

1818
for i in range(start_pos, len(text)):
1919
char = text[i]
20-
20+
2121
# Handle quote state
2222
if not in_quotes and char in ("'", '"', '`'):
2323
in_quotes = True
@@ -32,7 +32,7 @@ def find_enum_definition_end(text: str, start_pos: int) -> int:
3232
in_quotes = False
3333
quote_char = None
3434
continue
35-
35+
3636
# Only process parentheses when not in quotes
3737
if not in_quotes:
3838
if char == '(':
@@ -41,9 +41,15 @@ def find_enum_definition_end(text: str, start_pos: int) -> int:
4141
open_parens -= 1
4242
if open_parens == 0:
4343
return i
44-
45-
# If we get here, the definition is malformed
46-
raise ValueError("Unbalanced parentheses in enum definition")
44+
45+
# If we get here, the definition is malformed - provide detailed error info
46+
raise ValueError(
47+
f"Unbalanced parentheses in enum definition. "
48+
f"Input text: {text!r}, "
49+
f"Start position: {start_pos}, "
50+
f"Open parentheses remaining: {open_parens}, "
51+
f"Still in quotes: {in_quotes} (quote_char={quote_char!r})"
52+
)
4753

4854

4955
def extract_field_components(line: str) -> Tuple[str, str, List[str]]:

0 commit comments

Comments
 (0)