@@ -157,8 +157,13 @@ def find(self, query: Mapping = None, limit: tuple = None) -> List[Document | No
157157
158158 if limit :
159159 if len (limit ) == 2 :
160+
160161 _limit_start = limit [0 ]
161162 _limit_end = limit [1 ]
163+
164+ # check if lower limit greater than upper limit
165+ if _limit_start > _limit_end :
166+ raise ValueError ("limit[0] must be less than limit[1]." )
162167 else :
163168 raise ValueError (f"limit is a tuple of 2 values, { len (limit )} is given." )
164169
@@ -167,7 +172,12 @@ def find(self, query: Mapping = None, limit: tuple = None) -> List[Document | No
167172 # Check if it has a limit or not. If it has a limit do limit specific tasks.
168173 # Else return the whole Collection.
169174 if limit is not None :
170- _result = self ._collection [_limit_start : _limit_end ]
175+
176+ # check if lower limit is valid or not
177+ if _limit_start >= len (self ._collection ):
178+ raise ValueError (f"Lower limit should be smaller than Collection length.\n It must be less than `{ len (self ._collection )} `. `{ _limit_start } ` is given." )
179+ else :
180+ _result = self ._collection [_limit_start : _limit_end ]
171181 else :
172182 _result = self ._collection
173183
@@ -189,8 +199,12 @@ def find(self, query: Mapping = None, limit: tuple = None) -> List[Document | No
189199 # Reset the cursor
190200 self ._reset_cursor ()
191201
192- # Travers limited result
193- _result = _result [_limit_start : _limit_end ]
202+ # check if lower limit is valid or not
203+ if _limit_start >= len (_result ):
204+ raise ValueError (f"lower limit should be smaller than length of result" )
205+ else :
206+ # Travers limited result
207+ _result = _result [_limit_start : _limit_end ]
194208
195209 else :
196210 for i in self ._collection :
0 commit comments