diff --git a/clairvoyance/entities/errors.py b/clairvoyance/entities/errors.py new file mode 100644 index 0000000..1472661 --- /dev/null +++ b/clairvoyance/entities/errors.py @@ -0,0 +1,2 @@ +class EndpointError(Exception): + pass diff --git a/clairvoyance/graphql.py b/clairvoyance/graphql.py index c590e8e..e85b4a6 100644 --- a/clairvoyance/graphql.py +++ b/clairvoyance/graphql.py @@ -94,7 +94,7 @@ def get_path_from_root( path_from_root: List[str] = [] if name not in self.types: - raise Exception(f'Type \'{name}\' not in schema!') + raise ValueError(f'Type \'{name}\' not in schema!') roots = [ self._schema['queryType']['name'] if self._schema['queryType'] else '', @@ -119,7 +119,7 @@ def get_path_from_root( found = True if not found: log().debug('get_path_from_root: Ran an iteration with no matches found') - raise Exception(f'Could not find path from root to \'{initial_name}\' \nCurrent path: {path_from_root}') + raise ValueError(f'Could not find path from root to \'{initial_name}\' \nCurrent path: {path_from_root}') # Prepend queryType or mutationType path_from_root.insert(0, name) @@ -158,7 +158,7 @@ def convert_path_to_document( elif self._schema['subscriptionType'] and path[0] == self._schema['subscriptionType']['name']: doc = f'subscription {{ {doc} }}' else: - raise Exception('Unknown operation type') + raise ValueError('Unknown operation type') return doc @@ -173,7 +173,7 @@ def __init__( non_null: bool = False, ) -> None: if not is_list and non_null_item: - raise Exception('elements can\'t be NON_NULL if TypeRef is not LIST') + raise ValueError('Elements can\'t be NON_NULL if TypeRef is not LIST') self.name = name self.kind = kind @@ -266,7 +266,7 @@ def field_or_arg_type_from_json(_json: Dict[str, Any]) -> 'TypeRef': is_list=True, ) else: - raise Exception(f'Unexpected type.kind: {_json["kind"]}') + raise ValueError(f'Unexpected type.kind: {_json["kind"]}') elif not _json['ofType']['ofType']['ofType']: actual_type = _json['ofType']['ofType'] @@ -286,7 +286,7 @@ def field_or_arg_type_from_json(_json: Dict[str, Any]) -> 'TypeRef': non_null_item=True, ) else: - raise Exception(f'Unexpected type.kind: {_json["kind"]}') + raise ValueError(f'Unexpected type.kind: {_json["kind"]}') elif not _json['ofType']['ofType']['ofType']['ofType']: actual_type = _json['ofType']['ofType']['ofType'] typ = TypeRef( @@ -297,7 +297,7 @@ def field_or_arg_type_from_json(_json: Dict[str, Any]) -> 'TypeRef': non_null=True, ) else: - raise Exception('Invalid field or arg (too many \'ofType\')') + raise ValueError('Invalid field or arg (too many \'ofType\')') return typ @@ -310,7 +310,7 @@ def __init__( args: List[InputValue] = None, ): if not typeref: - raise Exception(f'Can\'t create {name} Field from {typeref} TypeRef.') + raise ValueError(f'Can\'t create {name} Field from {typeref} TypeRef.') self.name = name self.type = typeref diff --git a/clairvoyance/oracle.py b/clairvoyance/oracle.py index 42b7bdc..d056be8 100644 --- a/clairvoyance/oracle.py +++ b/clairvoyance/oracle.py @@ -2,12 +2,12 @@ import asyncio import re -import sys import time from typing import Any, Dict, List, Optional, Set, Tuple from clairvoyance import graphql from clairvoyance.entities import GraphQLPrimitive +from clairvoyance.entities.errors import EndpointError from clairvoyance.entities.context import client, config, log from clairvoyance.entities.oracle import FuzzingContext from clairvoyance.utils import track @@ -421,11 +421,9 @@ async def __probation(document: str) -> Optional[graphql.TypeRef]: typeref = result if not typeref and context != FuzzingContext.ARGUMENT: - try: - raise Exception(f"""Unable to get TypeRef for {documents} in context {context}. - It is very likely that Field Suggestion is not fully enabled on this endpoint.""") - except Exception as e: - raise Exception(e) from e + error_message = f'Unable to get TypeRef for {documents} in context {context}. ' + error_message += 'It is very likely that Field Suggestion is not fully enabled on this endpoint.' + raise EndpointError(error_message) return typeref diff --git a/pyproject.toml b/pyproject.toml index 672b052..77ffe9c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "Clairvoyance" -version = "2.5.2" +version = "2.5.3" description = "Obtain GraphQL API Schema even if the introspection is not enabled" authors = [ "Nikita Stupin ",