1212 ExpressionExactMatch ,
1313)
1414from hed .models .query_util import Token
15+ from hed .errors .exceptions import HedQueryError
1516
1617
1718class QueryHandler :
@@ -76,7 +77,7 @@ def _get_next_token(self):
7677 """Returns the current token and advances the counter"""
7778 self .at_token += 1
7879 if self .at_token >= len (self .tokens ):
79- raise ValueError ("Parse error in get next token" )
80+ raise HedQueryError ("Parse error in get next token" )
8081 return self .tokens [self .at_token ]
8182
8283 def _next_token_is (self , kinds ):
@@ -94,7 +95,7 @@ def _parse(self, expression_string):
9495 expr = self ._handle_or_op ()
9596
9697 if self .at_token + 1 != len (self .tokens ):
97- raise ValueError ("Parse error in search string" )
98+ raise HedQueryError ("Parse error in search string" )
9899
99100 return expr
100101
@@ -137,7 +138,7 @@ def _handle_negation(self):
137138 if next_token == Token .LogicalNegation :
138139 interior = self ._handle_grouping_op ()
139140 if "?" in str (interior ):
140- raise ValueError (
141+ raise HedQueryError (
141142 "Cannot negate wildcards, or expressions that contain wildcards."
142143 "Use {required_expression : optional_expression}."
143144 )
@@ -152,13 +153,13 @@ def _handle_grouping_op(self):
152153 expr = self ._handle_or_op ()
153154 next_token = self ._next_token_is ([Token .LogicalGroupEnd ])
154155 if next_token != Token .LogicalGroupEnd :
155- raise ValueError ("Parse error: Missing closing paren" )
156+ raise HedQueryError ("Parse error: Missing closing paren" )
156157 elif next_token == Token .DescendantGroup :
157158 interior = self ._handle_or_op ()
158159 expr = ExpressionDescendantGroup (next_token , right = interior )
159160 next_token = self ._next_token_is ([Token .DescendantGroupEnd ])
160161 if next_token != Token .DescendantGroupEnd :
161- raise ValueError ("Parse error: Missing closing square bracket" )
162+ raise HedQueryError ("Parse error: Missing closing square bracket" )
162163 elif next_token == Token .ExactMatch :
163164 interior = self ._handle_or_op ()
164165 expr = ExpressionExactMatch (next_token , right = interior )
@@ -172,14 +173,14 @@ def _handle_grouping_op(self):
172173 expr .left = optional_portion
173174 next_token = self ._next_token_is ([Token .ExactMatchEnd ])
174175 if "~" in str (expr ):
175- raise ValueError (
176+ raise HedQueryError (
176177 "Cannot use negation in exact matching groups,"
177178 " as it's not clear what is being matched.\n "
178179 "{thing and ~(expression)} is allowed."
179180 )
180181
181182 if next_token is None :
182- raise ValueError ("Parse error: Missing closing curly bracket" )
183+ raise HedQueryError ("Parse error: Missing closing curly bracket" )
183184 else :
184185 next_token = self ._get_next_token ()
185186 if next_token and next_token .kind == Token .Wildcard :
0 commit comments