Skip to content

Commit

Permalink
Better error message filter (#1837)
Browse files Browse the repository at this point in the history
Co-authored-by: Håkon V. Treider <[email protected]>
  • Loading branch information
doctrino and haakonvt authored Jul 9, 2024
1 parent 4f49166 commit 1fd5044
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cognite/client/data_classes/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ def _validate_filter(
) -> None:
if filter is None or isinstance(filter, dict):
return
elif not isinstance(filter, Filter):
raise TypeError(f"Invalid filter type: {type(filter)}. Must be Filter or dict")

if not_supported := (filter._involved_filter_types() - supported_filters):
names = [f.__name__ for f in not_supported]
raise ValueError(f"The filters {names} are not supported for {api_name}")
Expand All @@ -247,6 +250,8 @@ class CompoundFilter(Filter, ABC):
_filter_name = "compound"

def __init__(self, *filters: Filter) -> None:
if not_flt := [flt for flt in filters if not isinstance(flt, Filter)]:
raise TypeError(f"One or more invalid filters, expected Filter, got: {not_flt}")
self._filters = filters

def _filter_body(self, camel_case_property: bool) -> list | dict:
Expand Down

0 comments on commit 1fd5044

Please sign in to comment.