From 8f63f2f100e33d551d742cc236b1a9dbdffc15ce Mon Sep 17 00:00:00 2001 From: Privat33r-dev Date: Wed, 10 Apr 2024 17:10:47 +0200 Subject: [PATCH 1/4] Raise correct exception type --- clairvoyance/graphql.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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 From 55f17be568514d01e2d710dcf9d5d4b678b3efe9 Mon Sep 17 00:00:00 2001 From: Privat33r-dev Date: Wed, 10 Apr 2024 17:21:47 +0200 Subject: [PATCH 2/4] Add new error type and simplify error raising --- clairvoyance/entities/errors.py | 2 ++ clairvoyance/oracle.py | 9 ++++----- 2 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 clairvoyance/entities/errors.py 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/oracle.py b/clairvoyance/oracle.py index 42b7bdc..98f6bd6 100644 --- a/clairvoyance/oracle.py +++ b/clairvoyance/oracle.py @@ -8,6 +8,7 @@ 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 +422,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 From a82166e8baf6df0a71828d857779af00d3c03605 Mon Sep 17 00:00:00 2001 From: Privat33r-dev Date: Wed, 10 Apr 2024 17:22:11 +0200 Subject: [PATCH 3/4] Remove unused import --- clairvoyance/oracle.py | 1 - 1 file changed, 1 deletion(-) diff --git a/clairvoyance/oracle.py b/clairvoyance/oracle.py index 98f6bd6..d056be8 100644 --- a/clairvoyance/oracle.py +++ b/clairvoyance/oracle.py @@ -2,7 +2,6 @@ import asyncio import re -import sys import time from typing import Any, Dict, List, Optional, Set, Tuple From 954b4973be027278beb1fc7c463a8ae9cee1f40c Mon Sep 17 00:00:00 2001 From: Privat33r-dev Date: Wed, 10 Apr 2024 18:13:53 +0200 Subject: [PATCH 4/4] Version bump to v.2.5.3 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ",