Skip to content

Commit

Permalink
Reenable pylint broad exception (open-telemetry#2536)
Browse files Browse the repository at this point in the history
  • Loading branch information
xrmx authored May 24, 2024
1 parent c1a51fd commit e640956
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -492,4 +492,4 @@ min-public-methods=2

# Exceptions that will emit a warning when being caught. Defaults to
# "Exception".
overgeneral-exceptions=Exception
overgeneral-exceptions=builtins.Exception
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from unittest.mock import MagicMock

import aiopg
import psycopg2

import opentelemetry.instrumentation.aiopg
from opentelemetry import trace as trace_api
Expand Down Expand Up @@ -384,7 +385,9 @@ def test_span_failed(self):
span.attributes[SpanAttributes.DB_STATEMENT], "Test query"
)
self.assertIs(span.status.status_code, trace_api.StatusCode.ERROR)
self.assertEqual(span.status.description, "Exception: Test Exception")
self.assertEqual(
span.status.description, "ProgrammingError: Test Exception"
)

def test_executemany(self):
db_integration = AiopgIntegration(self.tracer, "testcomponent")
Expand Down Expand Up @@ -570,17 +573,17 @@ class MockCursor:
# pylint: disable=unused-argument, no-self-use
async def execute(self, query, params=None, throw_exception=False):
if throw_exception:
raise Exception("Test Exception")
raise psycopg2.ProgrammingError("Test Exception")

# pylint: disable=unused-argument, no-self-use
async def executemany(self, query, params=None, throw_exception=False):
if throw_exception:
raise Exception("Test Exception")
raise psycopg2.ProgrammingError("Test Exception")

# pylint: disable=unused-argument, no-self-use
async def callproc(self, query, params=None, throw_exception=False):
if throw_exception:
raise Exception("Test Exception")
raise psycopg2.ProgrammingError("Test Exception")

def close(self):
pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ def rest_api_handler(event, context):


def handler_exc(event, context):
# pylint: disable=broad-exception-raised
raise Exception("500 internal server error")
Original file line number Diff line number Diff line change
Expand Up @@ -419,16 +419,19 @@ def __init__(self) -> None:
# pylint: disable=unused-argument, no-self-use
def execute(self, query, params=None, throw_exception=False):
if throw_exception:
# pylint: disable=broad-exception-raised
raise Exception("Test Exception")

# pylint: disable=unused-argument, no-self-use
def executemany(self, query, params=None, throw_exception=False):
if throw_exception:
# pylint: disable=broad-exception-raised
raise Exception("Test Exception")
self.query = query
self.params = params

# pylint: disable=unused-argument, no-self-use
def callproc(self, query, params=None, throw_exception=False):
if throw_exception:
# pylint: disable=broad-exception-raised
raise Exception("Test Exception")
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ def response_hook(span, response):


def request_hook_with_exception(_span, _request):
raise Exception()
raise Exception() # pylint: disable=broad-exception-raised


def response_hook_with_exception(_span, _response):
raise Exception()
raise Exception() # pylint: disable=broad-exception-raised


@pytest.mark.asyncio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ def response_hook(span, response):


def request_hook_with_exception(_span, _request):
raise Exception()
raise Exception() # pylint: disable=broad-exception-raised


def response_hook_with_exception(_span, _response):
raise Exception()
raise Exception() # pylint: disable=broad-exception-raised


class TestHooks(TestBase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ def __init__(self, *args, **kwargs):
# pylint: disable=unused-argument, no-self-use
async def execute(self, query, params=None, throw_exception=False):
if throw_exception:
raise Exception("Test Exception")
raise psycopg.Error("Test Exception")

# pylint: disable=unused-argument, no-self-use
async def executemany(self, query, params=None, throw_exception=False):
if throw_exception:
raise Exception("Test Exception")
raise psycopg.Error("Test Exception")

# pylint: disable=unused-argument, no-self-use
async def callproc(self, query, params=None, throw_exception=False):
if throw_exception:
raise Exception("Test Exception")
raise psycopg.Error("Test Exception")

async def __aenter__(self, *args, **kwargs):
return self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def timeout_exception_callback(*_, **__):

@staticmethod
def base_exception_callback(*_, **__):
raise Exception("test")
raise Exception("test") # pylint: disable=broad-exception-raised

def assert_span(self, exporter=None, num_spans=1):
if exporter is None:
Expand Down

0 comments on commit e640956

Please sign in to comment.