diff --git a/src/linkahead/cached.py b/src/linkahead/cached.py index 121e26149179b772068863bcc4b183c4b151bd29..eaf24da0d79b643dea67116f428d906f3d0db784 100644 --- a/src/linkahead/cached.py +++ b/src/linkahead/cached.py @@ -126,20 +126,24 @@ def _cached_access(kind: AccessType, value: Union[str, int], unique: bool = True try: if kind == AccessType.QUERY: - assert isinstance(value, str), f"If kind is QUERY, value must be a string, not { - type(value)}." + if not isinstance(value, str): + raise TypeError( + f"If AccessType is QUERY, value must be a string, not {type(value)}.") return execute_query(value, unique=unique) if kind == AccessType.NAME: - assert isinstance(value, str), f"If kind is NAME, value must be a string, not { - type(value)}." + if not isinstance(value, str): + raise TypeError( + f"If AccessType is NAME, value must be a string, not {type(value)}.") return get_entity.get_entity_by_name(value) if kind == AccessType.EID: - assert isinstance(value, (str, int)), f"If kind is EID, value must be a string or int, not { - type(value)}." + if not isinstance(value, (str, int)): + raise TypeError( + f"If AccessType is EID, value must be a string or int, not {type(value)}.") return get_entity.get_entity_by_id(value) if kind == AccessType.PATH: - assert isinstance(value, str), f"If kind is PATH, value must be a string, not { - type(value)}." + if not isinstance(value, str): + raise TypeError( + f"If AccessType is PATH, value must be a string, not {type(value)}.") return get_entity.get_entity_by_path(value) except (QueryNotUniqueError, EmptyUniqueQueryError) as exc: return exc