Added better exceptions

This commit is contained in:
2021-07-27 09:41:51 +02:00
parent e0b7728719
commit 5e5d86cf94
11 changed files with 99 additions and 20 deletions

View File

@@ -1,9 +1,13 @@
from typing import Optional
from cpl_query.exceptions import ArgumentNoneException, ExceptionArgument
from cpl_query.extension.iterable_abc import IterableABC
def single_query(_list: IterableABC) -> any:
if _list is None:
raise ArgumentNoneException(ExceptionArgument.list)
if len(_list) > 1:
raise Exception('Found more than one element')
elif len(_list) == 0:
@@ -13,6 +17,9 @@ def single_query(_list: IterableABC) -> any:
def single_or_default_query(_list: IterableABC) -> Optional[any]:
if _list is None:
raise ArgumentNoneException(ExceptionArgument.list)
if len(_list) > 1:
raise Exception('Index out of range')
elif len(_list) == 0: