gurudesh/pytracebugs huggingface dataset:
# Buggy code
def cross(a, b):
    r"""Computes cross product between two vectors.

    .. math::

        \vec{w} = \vec{u} \times \vec{v} = \begin{vmatrix}
            u_{y} & y_{z} \\
            v_{y} & v_{z}
            \end{vmatrix}\vec{i} - \begin{vmatrix}
            u_{x} & u_{z} \\
            v_{x} & v_{z}
            \end{vmatrix}\vec{j} + \begin{vmatrix}
            u_{x} & u_{y} \\
            v_{x} & v_{y}
            \end{vmatrix}\vec{k}

    Parameters
    ----------

    a : ndarray
        3 Dimension vector.
    b : ndarray
        3 Dimension vector.

    Examples
    --------
    >>> from poliastro.core.util import cross
    >>> from astropy import units as u
    >>> i = [1, 0, 0] * u.m
    >>> j = [0, 1, 0] * u.m
    >>> cross(i, j)
    array([0., 0., 1.])

    Note
    -----
    np.cross is not supported in numba nopython mode, see
    https://github.com/numba/numba/issues/2978

    """

    return np.array(
        (
            a[1] * b[2] - a[2] * b[1],
            a[2] * b[0] - a[0] * b[2],
            a[0] * b[1] - a[1] * b[0],
        )
    )


# Traceback (astropy.units.core.UnitConversionError)
_____________________ [doctest] poliastro.core.util.cross ______________________
143     b : ndarray
144         3 Dimension vector.
145
146     Examples
147     --------
148     >>> from poliastro.core.util import cross
149     >>> from astropy import units as u
150     >>> i = [1, 0, 0] * u.m
151     >>> j = [0, 1, 0] * u.m
152     >>> cross(i, j)
UNEXPECTED EXCEPTION: TypeError('only dimensionless scalar quantities can be converted to Python scalars')
Traceback (most recent call last):

File "/usr/lib/python3/dist-packages/astropy/units/quantity.py", line 715, in to_value
scale = self.unit._to(unit)

File "/usr/lib/python3/dist-packages/astropy/units/core.py", line 953, in _to
"'{0!r}' is not a scaled version of '{1!r}'".format(self, other))

astropy.units.core.UnitConversionError: 'Unit("m2")' is not a scaled version of 'Unit(dimensionless)'

# Fixed code
def cross(a, b):
    r"""Computes cross product between two vectors.

    .. math::

        \vec{w} = \vec{u} \times \vec{v} = \begin{vmatrix}
            u_{y} & y_{z} \\
            v_{y} & v_{z}
            \end{vmatrix}\vec{i} - \begin{vmatrix}
            u_{x} & u_{z} \\
            v_{x} & v_{z}
            \end{vmatrix}\vec{j} + \begin{vmatrix}
            u_{x} & u_{y} \\
            v_{x} & v_{y}
            \end{vmatrix}\vec{k}

    Parameters
    ----------

    a : ndarray
        3 Dimension vector.
    b : ndarray
        3 Dimension vector.

    Examples
    --------
    >>> i = np.array([1., 0., 0.])
    >>> j = np.array([0., 1., 0.])
    >>> cross(i, j)
    array([0., 0., 1.])

    Note
    -----
    np.cross is not supported in numba nopython mode, see
    https://github.com/numba/numba/issues/2978

    """

    return np.array(
        (
            a[1] * b[2] - a[2] * b[1],
            a[2] * b[0] - a[0] * b[2],
            a[0] * b[1] - a[1] * b[0],
        )
    )
# Buggy code
def _wrap_init_error(init_error):
    # type: (F) -> F
    def sentry_init_error(*args, **kwargs):
        # type: (*Any, **Any) -> Any

        hub = Hub.current
        integration = hub.get_integration(AwsLambdaIntegration)
        if integration is None:
            return init_error(*args, **kwargs)

        # If an integration is there, a client has to be there.
        client = hub.client  # type: Any

        with capture_internal_exceptions():
            with hub.configure_scope() as scope:
                scope.clear_breadcrumbs()

            exc_info = sys.exc_info()
            if exc_info and all(exc_info):
                event, hint = event_from_exception(
                    exc_info,
                    client_options=client.options,
                    mechanism={"type": "aws_lambda", "handled": False},
                )
                hub.capture_event(event, hint=hint)

        return init_error(*args, **kwargs)

    return sentry_init_error  # type: ignore


# Traceback (AttributeError)
[ERROR] AttributeError: 'list' object has no attribute 'get'
Traceback (most recent call last):
File "/var/task/sentry_sdk/integrations/aws_lambda.py", line 106, in sentry_handler
headers = event.get("headers",
{}
)

# Fixed code
def _wrap_init_error(init_error):
    # type: (F) -> F
    def sentry_init_error(*args, **kwargs):
        # type: (*Any, **Any) -> Any

        hub = Hub.current
        integration = hub.get_integration(AwsLambdaIntegration)
        if integration is None:
            return init_error(*args, **kwargs)

        # If an integration is there, a client has to be there.
        client = hub.client  # type: Any

        with capture_internal_exceptions():
            with hub.configure_scope() as scope:
                scope.clear_breadcrumbs()

            exc_info = sys.exc_info()
            if exc_info and all(exc_info):
                sentry_event, hint = event_from_exception(
                    exc_info,
                    client_options=client.options,
                    mechanism={"type": "aws_lambda", "handled": False},
                )
                hub.capture_event(sentry_event, hint=hint)

        return init_error(*args, **kwargs)

    return sentry_init_error  # type: ignore
# Buggy code
def sentry_init_error(*args, **kwargs):
    # type: (*Any, **Any) -> Any

    hub = Hub.current
    integration = hub.get_integration(AwsLambdaIntegration)
    if integration is None:
        return init_error(*args, **kwargs)

    # If an integration is there, a client has to be there.
    client = hub.client  # type: Any

    with capture_internal_exceptions():
        with hub.configure_scope() as scope:
            scope.clear_breadcrumbs()

        exc_info = sys.exc_info()
        if exc_info and all(exc_info):
            event, hint = event_from_exception(
                exc_info,
                client_options=client.options,
                mechanism={"type": "aws_lambda", "handled": False},
            )
            hub.capture_event(event, hint=hint)

    return init_error(*args, **kwargs)


# Traceback (AttributeError)
[ERROR] AttributeError: 'list' object has no attribute 'get'
Traceback (most recent call last):
File "/var/task/sentry_sdk/integrations/aws_lambda.py", line 106, in sentry_handler
headers = event.get("headers",
{}
)

# Fixed code
def sentry_init_error(*args, **kwargs):
    # type: (*Any, **Any) -> Any

    hub = Hub.current
    integration = hub.get_integration(AwsLambdaIntegration)
    if integration is None:
        return init_error(*args, **kwargs)

    # If an integration is there, a client has to be there.
    client = hub.client  # type: Any

    with capture_internal_exceptions():
        with hub.configure_scope() as scope:
            scope.clear_breadcrumbs()

        exc_info = sys.exc_info()
        if exc_info and all(exc_info):
            sentry_event, hint = event_from_exception(
                exc_info,
                client_options=client.options,
                mechanism={"type": "aws_lambda", "handled": False},
            )
            hub.capture_event(sentry_event, hint=hint)

    return init_error(*args, **kwargs)
# Buggy code
def _get_url(event, context):
    # type: (Any, Any) -> str
    path = event.get("path", None)
    headers = event.get("headers", {})
    host = headers.get("Host", None)
    proto = headers.get("X-Forwarded-Proto", None)
    if proto and host and path:
        return "{}://{}{}".format(proto, host, path)
    return "awslambda:///{}".format(context.function_name)


# Traceback (AttributeError)
[ERROR] AttributeError: 'list' object has no attribute 'get'
Traceback (most recent call last):
File "/var/task/sentry_sdk/integrations/aws_lambda.py", line 106, in sentry_handler
headers = event.get("headers",
{}
)

# Fixed code
def _get_url(aws_event, aws_context):
    # type: (Any, Any) -> str
    path = aws_event.get("path", None)
    headers = aws_event.get("headers", {})
    host = headers.get("Host", None)
    proto = headers.get("X-Forwarded-Proto", None)
    if proto and host and path:
        return "{}://{}{}".format(proto, host, path)
    return "awslambda:///{}".format(aws_context.function_name)
# Buggy code
def _get_cloudwatch_logs_url(context, start_time):
    # type: (Any, datetime) -> str
    """
    Generates a CloudWatchLogs console URL based on the context object

    Arguments:
        context {Any} -- context from lambda handler

    Returns:
        str -- AWS Console URL to logs.
    """
    formatstring = "%Y-%m-%dT%H:%M:%SZ"

    url = (
        "https://console.aws.amazon.com/cloudwatch/home?region={region}"
        "#logEventViewer:group={log_group};stream={log_stream}"
        ";start={start_time};end={end_time}"
    ).format(
        region=environ.get("AWS_REGION"),
        log_group=context.log_group_name,
        log_stream=context.log_stream_name,
        start_time=(start_time - timedelta(seconds=1)).strftime(formatstring),
        end_time=(datetime.utcnow() + timedelta(seconds=2)).strftime(formatstring),
    )

    return url


# Traceback (AttributeError)
[ERROR] AttributeError: 'list' object has no attribute 'get'
Traceback (most recent call last):
File "/var/task/sentry_sdk/integrations/aws_lambda.py", line 106, in sentry_handler
headers = event.get("headers",
{}
)

# Fixed code
def _get_cloudwatch_logs_url(aws_context, start_time):
    # type: (Any, datetime) -> str
    """
    Generates a CloudWatchLogs console URL based on the context object

    Arguments:
        aws_context {Any} -- context from lambda handler

    Returns:
        str -- AWS Console URL to logs.
    """
    formatstring = "%Y-%m-%dT%H:%M:%SZ"

    url = (
        "https://console.aws.amazon.com/cloudwatch/home?region={region}"
        "#logEventViewer:group={log_group};stream={log_stream}"
        ";start={start_time};end={end_time}"
    ).format(
        region=environ.get("AWS_REGION"),
        log_group=aws_context.log_group_name,
        log_stream=aws_context.log_stream_name,
        start_time=(start_time - timedelta(seconds=1)).strftime(formatstring),
        end_time=(datetime.utcnow() + timedelta(seconds=2)).strftime(formatstring),
    )

    return url
# Buggy code
def patch_channels_asgi_handler_impl(cls):
    # type: (Any) -> None

    from sentry_sdk.integrations.django import DjangoIntegration

    old_app = cls.__call__

    async def sentry_patched_asgi_handler(self, receive, send):
        # type: (Any, Any, Any) -> Any
        if Hub.current.get_integration(DjangoIntegration) is None:
            return await old_app(self, receive, send)

        middleware = SentryAsgiMiddleware(
            lambda _scope: old_app.__get__(self, cls), unsafe_context_data=True
        )

        return await middleware(self.scope)(receive, send)

    cls.__call__ = sentry_patched_asgi_handler


# Traceback (TypeError)
Exception inside application: sentry_patched_asgi_handler() takes 3 positional arguments but 4 were given
Traceback (most recent call last):
File "env/lib/python3.8/site-packages/channels/routing.py", line 71, in __call__
return await application(scope, receive, send)
TypeError: sentry_patched_asgi_handler() takes 3 positional arguments but 4 were given
HTTP POST /api/v2/auth/login 500 [0.67, 127.0.0.1:37750]

# Fixed code
def patch_channels_asgi_handler_impl(cls):
    # type: (Any) -> None

    import channels  # type: ignore
    from sentry_sdk.integrations.django import DjangoIntegration

    if channels.__version__ < "3.0.0":
        old_app = cls.__call__

        async def sentry_patched_asgi_handler(self, receive, send):
            # type: (Any, Any, Any) -> Any
            if Hub.current.get_integration(DjangoIntegration) is None:
                return await old_app(self, receive, send)

            middleware = SentryAsgiMiddleware(
                lambda _scope: old_app.__get__(self, cls), unsafe_context_data=True
            )

            return await middleware(self.scope)(receive, send)

        cls.__call__ = sentry_patched_asgi_handler

    else:
        # The ASGI handler in Channels >= 3 has the same signature as
        # the Django handler.
        patch_django_asgi_handler_impl(cls)
# Buggy code
def __init__(self, app):
    # type: (Any) -> None
    self.app = app


# Traceback (TypeError)
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/uvicorn/protocols/http/httptools_impl.py", line 385, in run_asgi
result = await app(self.scope, self.receive, self.send)
File "/usr/local/lib/python3.7/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__
return await self.app(scope, receive, send)
File "/usr/local/lib/python3.7/site-packages/uvicorn/middleware/asgi2.py", line 7, in __call__
await instance(receive, send)
File "/usr/local/lib/python3.7/site-packages/sentry_sdk/integrations/asgi.py", line 54, in run_asgi2
scope, lambda: self.app(scope)(receive, send)
File "/usr/local/lib/python3.7/site-packages/sentry_sdk/integrations/asgi.py", line 93, in _run_app
raise exc from None
File "/usr/local/lib/python3.7/site-packages/sentry_sdk/integrations/asgi.py", line 90, in _run_app
return await callback()
File "/usr/local/lib/python3.7/site-packages/sentry_sdk/integrations/asgi.py", line 54, in <lambda>
scope, lambda: self.app(scope)(receive, send)
TypeError: __call__() missing 2 required positional arguments: 'receive' and 'send'

# Fixed code
def __init__(self, app):
    # type: (Any) -> None
    self.app = app

    if _looks_like_asgi3(app):
        self.__call__ = self._run_asgi3  # type: Callable[..., Any]
    else:
        self.__call__ = self._run_asgi2
# Buggy code
def _timed_queue_join(self, timeout):
    # type: (float) -> bool
    deadline = time() + timeout
    queue = self._queue
    queue.all_tasks_done.acquire()  # type: ignore
    try:
        while queue.unfinished_tasks:  # type: ignore
            delay = deadline - time()
            if delay <= 0:
                return False
            queue.all_tasks_done.wait(timeout=delay)  # type: ignore
        return True
    finally:
        queue.all_tasks_done.release()  # type: ignore


# Traceback (AttributeError)
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "/Users/jibanez/API/.conda/envs/cimrender/lib/python3.6/site-packages/sentry_sdk/worker.py", line 84, in flush
self._wait_flush(timeout, callback)
File "/Users/jibanez/API/.conda/envs/cimrender/lib/python3.6/site-packages/sentry_sdk/worker.py", line 90, in _wait_flush
if not self._timed_queue_join(initial_timeout):
File "/Users/jibanez/API/.conda/envs/cimrender/lib/python3.6/site-packages/sentry_sdk/worker.py", line 48, in _timed_queue_join
queue.all_tasks_done.acquire()  # type: ignore
AttributeError: 'Queue' object has no attribute 'all_tasks_done'

# Fixed code
def _timed_queue_join(self, timeout):
    # type: (float) -> bool
    deadline = time() + timeout
    queue = self._queue

    real_all_tasks_done = getattr(queue, "all_tasks_done", None)  # type: Optional[Any]
    if real_all_tasks_done is not None:
        real_all_tasks_done.acquire()
        all_tasks_done = real_all_tasks_done  # type: Optional[Any]
    elif queue.__module__.startswith("eventlet."):
        all_tasks_done = getattr(queue, "_cond", None)
    else:
        all_tasks_done = None

    try:
        while queue.unfinished_tasks:  # type: ignore
            delay = deadline - time()
            if delay <= 0:
                return False
            if all_tasks_done is not None:
                all_tasks_done.wait(timeout=delay)
            else:
                # worst case, we just poll the number of remaining tasks
                sleep(0.1)

        return True
    finally:
        if real_all_tasks_done is not None:
            real_all_tasks_done.release()  # type: ignore
# Buggy code
def setup_once():
    # type: () -> None
    old_start = Thread.start

    def sentry_start(self, *a, **kw):
        hub = Hub.current
        integration = hub.get_integration(ThreadingIntegration)
        if integration is not None:
            if not integration.propagate_hub:
                hub_ = None
            else:
                hub_ = Hub(hub)

            self.run = _wrap_run(hub_, self.run)

        return old_start(self, *a, **kw)  # type: ignore

    Thread.start = sentry_start  # type: ignore


# Traceback (OSError)
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "/Users/tony.li/miniconda3/lib/python3.7/concurrent/futures/process.py", line 101, in _python_exit
thread_wakeup.wakeup()
File "/Users/tony.li/miniconda3/lib/python3.7/concurrent/futures/process.py", line 89, in wakeup
self._writer.send_bytes(b"")
File "/Users/tony.li/miniconda3/lib/python3.7/multiprocessing/connection.py", line 183, in send_bytes
self._check_closed()
File "/Users/tony.li/miniconda3/lib/python3.7/multiprocessing/connection.py", line 136, in _check_closed
raise OSError("handle is closed")
OSError: handle is closed

# Fixed code
def setup_once():
    # type: () -> None
    old_start = Thread.start

    def sentry_start(self, *a, **kw):
        hub = Hub.current
        integration = hub.get_integration(ThreadingIntegration)
        if integration is not None:
            if not integration.propagate_hub:
                hub_ = None
            else:
                hub_ = Hub(hub)
            # Patching instance methods in `start()` creates a reference cycle if
            # done in a naive way. See
            # https://github.com/getsentry/sentry-python/pull/434
            #
            # In threading module, using current_thread API will access current thread instance
            # without holding it to avoid a reference cycle in an easier way.
            self.run = _wrap_run(hub_, self.run.__func__)

        return old_start(self, *a, **kw)  # type: ignore

    Thread.start = sentry_start  # type: ignore
# Buggy code
def sentry_start(self, *a, **kw):
    hub = Hub.current
    integration = hub.get_integration(ThreadingIntegration)
    if integration is not None:
        if not integration.propagate_hub:
            hub_ = None
        else:
            hub_ = Hub(hub)

        self.run = _wrap_run(hub_, self.run)

    return old_start(self, *a, **kw)  # type: ignore


# Traceback (OSError)
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "/Users/tony.li/miniconda3/lib/python3.7/concurrent/futures/process.py", line 101, in _python_exit
thread_wakeup.wakeup()
File "/Users/tony.li/miniconda3/lib/python3.7/concurrent/futures/process.py", line 89, in wakeup
self._writer.send_bytes(b"")
File "/Users/tony.li/miniconda3/lib/python3.7/multiprocessing/connection.py", line 183, in send_bytes
self._check_closed()
File "/Users/tony.li/miniconda3/lib/python3.7/multiprocessing/connection.py", line 136, in _check_closed
raise OSError("handle is closed")
OSError: handle is closed

# Fixed code
def sentry_start(self, *a, **kw):
    hub = Hub.current
    integration = hub.get_integration(ThreadingIntegration)
    if integration is not None:
        if not integration.propagate_hub:
            hub_ = None
        else:
            hub_ = Hub(hub)
        # Patching instance methods in `start()` creates a reference cycle if
        # done in a naive way. See
        # https://github.com/getsentry/sentry-python/pull/434
        #
        # In threading module, using current_thread API will access current thread instance
        # without holding it to avoid a reference cycle in an easier way.
        self.run = _wrap_run(hub_, self.run.__func__)

    return old_start(self, *a, **kw)  # type: ignore
# Buggy code
def _wrap_run(parent_hub, old_run):
    def run(*a, **kw):
        hub = parent_hub or Hub.current

        with hub:
            try:
                return old_run(*a, **kw)
            except Exception:
                reraise(*_capture_exception())

    return run


# Traceback (OSError)
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "/Users/tony.li/miniconda3/lib/python3.7/concurrent/futures/process.py", line 101, in _python_exit
thread_wakeup.wakeup()
File "/Users/tony.li/miniconda3/lib/python3.7/concurrent/futures/process.py", line 89, in wakeup
self._writer.send_bytes(b"")
File "/Users/tony.li/miniconda3/lib/python3.7/multiprocessing/connection.py", line 183, in send_bytes
self._check_closed()
File "/Users/tony.li/miniconda3/lib/python3.7/multiprocessing/connection.py", line 136, in _check_closed
raise OSError("handle is closed")
OSError: handle is closed

# Fixed code
def _wrap_run(parent_hub, old_run_func):
    def run(*a, **kw):
        hub = parent_hub or Hub.current
        with hub:
            try:
                self = current_thread()
                return old_run_func(self, *a, **kw)
            except Exception:
                reraise(*_capture_exception())

    return run
# Buggy code
def run(*a, **kw):
    hub = parent_hub or Hub.current

    with hub:
        try:
            return old_run(*a, **kw)
        except Exception:
            reraise(*_capture_exception())


# Traceback (OSError)
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "/Users/tony.li/miniconda3/lib/python3.7/concurrent/futures/process.py", line 101, in _python_exit
thread_wakeup.wakeup()
File "/Users/tony.li/miniconda3/lib/python3.7/concurrent/futures/process.py", line 89, in wakeup
self._writer.send_bytes(b"")
File "/Users/tony.li/miniconda3/lib/python3.7/multiprocessing/connection.py", line 183, in send_bytes
self._check_closed()
File "/Users/tony.li/miniconda3/lib/python3.7/multiprocessing/connection.py", line 136, in _check_closed
raise OSError("handle is closed")
OSError: handle is closed

# Fixed code
def run(*a, **kw):
    hub = parent_hub or Hub.current
    with hub:
        try:
            self = current_thread()
            return old_run_func(self, *a, **kw)
        except Exception:
            reraise(*_capture_exception())
# Buggy code
def format_sql(sql, params):
    # type: (Any, Any) -> Tuple[str, List[str]]
    rv = []

    if isinstance(params, dict):
        # convert sql with named parameters to sql with unnamed parameters
        conv = _FormatConverter(params)
        if params:
            sql = sql_to_string(sql)
            sql = sql % conv
            params = conv.params
        else:
            params = ()

    for param in params or ():
        if param is None:
            rv.append("NULL")
        param = safe_repr(param)
        rv.append(param)

    return sql, rv


# Traceback (TypeError)
$ ./manage.py test-sentry
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/ph/ph/app/management/commands/test-sentry.py", line 18, in handle
'foo': 'foo',
File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 100, in execute
return super().execute(sql, params)
File "/usr/local/lib/python3.6/site-packages/sentry_sdk/integrations/django/__init__.py", line 273, in execute
record_sql(sql, params)
File "/usr/local/lib/python3.6/site-packages/sentry_sdk/integrations/django/__init__.py", line 240, in record_sql
real_sql, real_params = format_sql(sql, params)
File "/usr/local/lib/python3.6/site-packages/sentry_sdk/integrations/django/__init__.py", line 222, in format_sql
sql = sql % conv
TypeError: unsupported operand type(s) for %: 'Composed' and '_FormatConverter'
$

# Fixed code
def format_sql(sql, params):
    # type: (Any, Any) -> Tuple[str, List[str]]
    rv = []

    if isinstance(params, dict):
        # convert sql with named parameters to sql with unnamed parameters
        conv = _FormatConverter(params)
        if params:
            sql = sql % conv
            params = conv.params
        else:
            params = ()

    for param in params or ():
        if param is None:
            rv.append("NULL")
        param = safe_repr(param)
        rv.append(param)

    return sql, rv
# Buggy code
def record_sql(sql, params):
    # type: (Any, Any) -> None
    hub = Hub.current
    if hub.get_integration(DjangoIntegration) is None:
        return
    real_sql, real_params = format_sql(sql, params)

    if real_params:
        try:
            real_sql = format_and_strip(real_sql, real_params)
        except Exception:
            pass

    hub.add_breadcrumb(message=real_sql, category="query")


# Traceback (TypeError)
$ ./manage.py test-sentry
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/ph/ph/app/management/commands/test-sentry.py", line 18, in handle
'foo': 'foo',
File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 100, in execute
return super().execute(sql, params)
File "/usr/local/lib/python3.6/site-packages/sentry_sdk/integrations/django/__init__.py", line 273, in execute
record_sql(sql, params)
File "/usr/local/lib/python3.6/site-packages/sentry_sdk/integrations/django/__init__.py", line 240, in record_sql
real_sql, real_params = format_sql(sql, params)
File "/usr/local/lib/python3.6/site-packages/sentry_sdk/integrations/django/__init__.py", line 222, in format_sql
sql = sql % conv
TypeError: unsupported operand type(s) for %: 'Composed' and '_FormatConverter'
$

# Fixed code
def record_sql(sql, params, cursor=None):
    # type: (Any, Any, Any) -> None
    hub = Hub.current
    if hub.get_integration(DjangoIntegration) is None:
        return

    with capture_internal_exceptions():
        if cursor and hasattr(cursor, "mogrify"):  # psycopg2
            real_sql = cursor.mogrify(sql, params)
            with capture_internal_exceptions():
                if isinstance(real_sql, bytes):
                    real_sql = real_sql.decode(cursor.connection.encoding)
        else:
            real_sql, real_params = format_sql(sql, params)

            if real_params:
                try:
                    real_sql = format_and_strip(real_sql, real_params)
                except Exception:
                    pass
        hub.add_breadcrumb(message=real_sql, category="query")
# Buggy code
def record_many_sql(sql, param_list):
    for params in param_list:
        record_sql(sql, params)


# Traceback (TypeError)
$ ./manage.py test-sentry
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/ph/ph/app/management/commands/test-sentry.py", line 18, in handle
'foo': 'foo',
File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 100, in execute
return super().execute(sql, params)
File "/usr/local/lib/python3.6/site-packages/sentry_sdk/integrations/django/__init__.py", line 273, in execute
record_sql(sql, params)
File "/usr/local/lib/python3.6/site-packages/sentry_sdk/integrations/django/__init__.py", line 240, in record_sql
real_sql, real_params = format_sql(sql, params)
File "/usr/local/lib/python3.6/site-packages/sentry_sdk/integrations/django/__init__.py", line 222, in format_sql
sql = sql % conv
TypeError: unsupported operand type(s) for %: 'Composed' and '_FormatConverter'
$

# Fixed code
def record_many_sql(sql, param_list, cursor):
    for params in param_list:
        record_sql(sql, params, cursor)
# Buggy code
def execute(self, sql, params=None):
    try:
        return real_execute(self, sql, params)
    finally:
        record_sql(sql, params)


# Traceback (TypeError)
$ ./manage.py test-sentry
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/ph/ph/app/management/commands/test-sentry.py", line 18, in handle
'foo': 'foo',
File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 100, in execute
return super().execute(sql, params)
File "/usr/local/lib/python3.6/site-packages/sentry_sdk/integrations/django/__init__.py", line 273, in execute
record_sql(sql, params)
File "/usr/local/lib/python3.6/site-packages/sentry_sdk/integrations/django/__init__.py", line 240, in record_sql
real_sql, real_params = format_sql(sql, params)
File "/usr/local/lib/python3.6/site-packages/sentry_sdk/integrations/django/__init__.py", line 222, in format_sql
sql = sql % conv
TypeError: unsupported operand type(s) for %: 'Composed' and '_FormatConverter'
$

# Fixed code
def execute(self, sql, params=None):
    try:
        return real_execute(self, sql, params)
    finally:
        record_sql(sql, params, self.cursor)
# Buggy code
def executemany(self, sql, param_list):
    try:
        return real_executemany(self, sql, param_list)
    finally:
        record_many_sql(sql, param_list)


# Traceback (TypeError)
$ ./manage.py test-sentry
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/ph/ph/app/management/commands/test-sentry.py", line 18, in handle
'foo': 'foo',
File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 100, in execute
return super().execute(sql, params)
File "/usr/local/lib/python3.6/site-packages/sentry_sdk/integrations/django/__init__.py", line 273, in execute
record_sql(sql, params)
File "/usr/local/lib/python3.6/site-packages/sentry_sdk/integrations/django/__init__.py", line 240, in record_sql
real_sql, real_params = format_sql(sql, params)
File "/usr/local/lib/python3.6/site-packages/sentry_sdk/integrations/django/__init__.py", line 222, in format_sql
sql = sql % conv
TypeError: unsupported operand type(s) for %: 'Composed' and '_FormatConverter'
$

# Fixed code
def executemany(self, sql, param_list):
    try:
        return real_executemany(self, sql, param_list)
    finally:
        record_many_sql(sql, param_list, self.cursor)
# Buggy code
def sentry_build_tracer(name, task, *args, **kwargs):
    # Need to patch both methods because older celery sometimes
    # short-circuits to task.run if it thinks it's safe.
    task.__call__ = _wrap_task_call(task.__call__)
    task.run = _wrap_task_call(task.run)
    return _wrap_tracer(task, old_build_tracer(name, task, *args, **kwargs))


# Traceback (RuntimeError)
[2019-03-08 21:24:21,117: ERROR/ForkPoolWorker-31] Task simple_task[d6e959b1-7253-4e55-861d-c1968ae14e1c] raised unexpected: RuntimeError('No active exception to reraise')
Traceback (most recent call last):
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/celery/app/trace.py", line 382, in trace_task
R = retval = fun(*args, **kwargs)
File "/Users/okomarov/Documents/repos/myproject/web/celery_factory.py", line 28, in __call__
return TaskBase.__call__(self, *args, **kwargs)
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/celery/app/trace.py", line 641, in __protected_call__
return self.run(*args, **kwargs)
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/sentry_sdk/integrations/celery.py", line 66, in _inner
reraise(*_capture_exception())
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/sentry_sdk/_compat.py", line 52, in reraise
raise value
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/sentry_sdk/integrations/celery.py", line 64, in _inner
return f(*args, **kwargs)
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/sentry_sdk/integrations/celery.py", line 66, in _inner
reraise(*_capture_exception())
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/sentry_sdk/_compat.py", line 52, in reraise
raise value
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/sentry_sdk/integrations/celery.py", line 64, in _inner
return f(*args, **kwargs)
File "/Users/okomarov/Documents/repos/myproject/web/simple_task.py", line 4, in simple_task
raise Exception("Testing Celery exception")
RuntimeError: No active exception to reraise

# Fixed code
def sentry_build_tracer(name, task, *args, **kwargs):
    # Need to patch both methods because older celery sometimes
    # short-circuits to task.run if it thinks it's safe.
    task.__call__ = _wrap_task_call(task, task.__call__)
    task.run = _wrap_task_call(task, task.run)
    return _wrap_tracer(task, old_build_tracer(name, task, *args, **kwargs))
# Buggy code
def _wrap_task_call(f):
    # Need to wrap task call because the exception is caught before we get to
    # see it. Also celery's reported stacktrace is untrustworthy.
    def _inner(*args, **kwargs):
        try:
            return f(*args, **kwargs)
        except Exception:
            reraise(*_capture_exception())

    return _inner


# Traceback (RuntimeError)
[2019-03-08 21:24:21,117: ERROR/ForkPoolWorker-31] Task simple_task[d6e959b1-7253-4e55-861d-c1968ae14e1c] raised unexpected: RuntimeError('No active exception to reraise')
Traceback (most recent call last):
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/celery/app/trace.py", line 382, in trace_task
R = retval = fun(*args, **kwargs)
File "/Users/okomarov/Documents/repos/myproject/web/celery_factory.py", line 28, in __call__
return TaskBase.__call__(self, *args, **kwargs)
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/celery/app/trace.py", line 641, in __protected_call__
return self.run(*args, **kwargs)
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/sentry_sdk/integrations/celery.py", line 66, in _inner
reraise(*_capture_exception())
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/sentry_sdk/_compat.py", line 52, in reraise
raise value
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/sentry_sdk/integrations/celery.py", line 64, in _inner
return f(*args, **kwargs)
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/sentry_sdk/integrations/celery.py", line 66, in _inner
reraise(*_capture_exception())
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/sentry_sdk/_compat.py", line 52, in reraise
raise value
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/sentry_sdk/integrations/celery.py", line 64, in _inner
return f(*args, **kwargs)
File "/Users/okomarov/Documents/repos/myproject/web/simple_task.py", line 4, in simple_task
raise Exception("Testing Celery exception")
RuntimeError: No active exception to reraise

# Fixed code
def _wrap_task_call(task, f):
    # Need to wrap task call because the exception is caught before we get to
    # see it. Also celery's reported stacktrace is untrustworthy.
    def _inner(*args, **kwargs):
        try:
            return f(*args, **kwargs)
        except Exception:
            exc_info = sys.exc_info()
            with capture_internal_exceptions():
                _capture_exception(task, exc_info)
            reraise(*exc_info)

    return _inner
# Buggy code
def _inner(*args, **kwargs):
    try:
        return f(*args, **kwargs)
    except Exception:
        reraise(*_capture_exception())


# Traceback (RuntimeError)
[2019-03-08 21:24:21,117: ERROR/ForkPoolWorker-31] Task simple_task[d6e959b1-7253-4e55-861d-c1968ae14e1c] raised unexpected: RuntimeError('No active exception to reraise')
Traceback (most recent call last):
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/celery/app/trace.py", line 382, in trace_task
R = retval = fun(*args, **kwargs)
File "/Users/okomarov/Documents/repos/myproject/web/celery_factory.py", line 28, in __call__
return TaskBase.__call__(self, *args, **kwargs)
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/celery/app/trace.py", line 641, in __protected_call__
return self.run(*args, **kwargs)
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/sentry_sdk/integrations/celery.py", line 66, in _inner
reraise(*_capture_exception())
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/sentry_sdk/_compat.py", line 52, in reraise
raise value
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/sentry_sdk/integrations/celery.py", line 64, in _inner
return f(*args, **kwargs)
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/sentry_sdk/integrations/celery.py", line 66, in _inner
reraise(*_capture_exception())
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/sentry_sdk/_compat.py", line 52, in reraise
raise value
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/sentry_sdk/integrations/celery.py", line 64, in _inner
return f(*args, **kwargs)
File "/Users/okomarov/Documents/repos/myproject/web/simple_task.py", line 4, in simple_task
raise Exception("Testing Celery exception")
RuntimeError: No active exception to reraise

# Fixed code
def _inner(*args, **kwargs):
    try:
        return f(*args, **kwargs)
    except Exception:
        exc_info = sys.exc_info()
        with capture_internal_exceptions():
            _capture_exception(task, exc_info)
        reraise(*exc_info)
# Buggy code
def _capture_exception():
    hub = Hub.current
    exc_info = sys.exc_info()

    if hub.get_integration(CeleryIntegration) is not None:
        event, hint = event_from_exception(
            exc_info,
            client_options=hub.client.options,
            mechanism={"type": "celery", "handled": False},
        )
        hub.capture_event(event, hint=hint)

    return exc_info


# Traceback (RuntimeError)
[2019-03-08 21:24:21,117: ERROR/ForkPoolWorker-31] Task simple_task[d6e959b1-7253-4e55-861d-c1968ae14e1c] raised unexpected: RuntimeError('No active exception to reraise')
Traceback (most recent call last):
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/celery/app/trace.py", line 382, in trace_task
R = retval = fun(*args, **kwargs)
File "/Users/okomarov/Documents/repos/myproject/web/celery_factory.py", line 28, in __call__
return TaskBase.__call__(self, *args, **kwargs)
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/celery/app/trace.py", line 641, in __protected_call__
return self.run(*args, **kwargs)
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/sentry_sdk/integrations/celery.py", line 66, in _inner
reraise(*_capture_exception())
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/sentry_sdk/_compat.py", line 52, in reraise
raise value
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/sentry_sdk/integrations/celery.py", line 64, in _inner
return f(*args, **kwargs)
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/sentry_sdk/integrations/celery.py", line 66, in _inner
reraise(*_capture_exception())
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/sentry_sdk/_compat.py", line 52, in reraise
raise value
File "/Users/okomarov/.virtualenvs/myenv/lib/python3.7/site-packages/sentry_sdk/integrations/celery.py", line 64, in _inner
return f(*args, **kwargs)
File "/Users/okomarov/Documents/repos/myproject/web/simple_task.py", line 4, in simple_task
raise Exception("Testing Celery exception")
RuntimeError: No active exception to reraise

# Fixed code
def _capture_exception(task, exc_info):
    hub = Hub.current

    if hub.get_integration(CeleryIntegration) is None:
        return
    if isinstance(exc_info[1], Retry):
        return
    if hasattr(task, "throws") and isinstance(exc_info[1], task.throws):
        return

    event, hint = event_from_exception(
        exc_info,
        client_options=hub.client.options,
        mechanism={"type": "celery", "handled": False},
    )

    hub.capture_event(event, hint=hint)
# Buggy code
def get_by_scope_and_name(cls, scope, name):
    """
    Get a key value store given a scope and name.

    :param scope: Scope which the key belongs to.
    :type scope: ``str``

    :param name: Name of the key.
    :type key: ``str``

    :rtype: :class:`KeyValuePairDB` or ``None``
    """
    query_result = cls.impl.query(scope=scope, name=name)

    if not query_result:
        msg = 'The key "%s" does not exist in the StackStorm datastore.'
        raise StackStormDBObjectNotFoundError(msg % name)

    return query_result.first() if query_result else None


# Traceback (StackStormDBObjectNotFoundError)
Jun 26 18:27:35 ip-10-15-1-121 gunicorn[184385]: 2020-06-26 18:27:35,134 ERROR [-] Failed to call controller function "get_one" for operation "st2api.controllers.v1.keyvalue:key_value_pair_controller.get_one": The key "aws_inspector.AWSInspector:us-east-2.last_start_time_" does not exist in the StackStorm datastore.
Jun 26 18:27:35 ip-10-15-1-121 gunicorn[184385]: Traceback (most recent call last):
Jun 26 18:27:35 ip-10-15-1-121 gunicorn[184385]:  File "/opt/stackstorm/st2/lib/python3.6/site-packages/st2common/router.py", line 515, in __call__
Jun 26 18:27:35 ip-10-15-1-121 gunicorn[184385]:    resp = func(**kw)
Jun 26 18:27:35 ip-10-15-1-121 gunicorn[184385]:  File "/opt/stackstorm/st2/lib/python3.6/site-packages/st2api/controllers/v1/keyvalue.py", line 124, in get_one
Jun 26 18:27:35 ip-10-15-1-121 gunicorn[184385]:    from_model_kwargs=from_model_kwargs
Jun 26 18:27:35 ip-10-15-1-121 gunicorn[184385]:  File "/opt/stackstorm/st2/lib/python3.6/site-packages/st2api/controllers/resource.py", line 402, in _get_one_by_scope_and_name
Jun 26 18:27:35 ip-10-15-1-121 gunicorn[184385]:    instance = self.access.get_by_scope_and_name(scope=scope, name=name)
Jun 26 18:27:35 ip-10-15-1-121 gunicorn[184385]:  File "/opt/stackstorm/st2/lib/python3.6/site-packages/st2common/persistence/keyvalue.py", line 115, in get_by_scope_and_name
Jun 26 18:27:35 ip-10-15-1-121 gunicorn[184385]:    raise StackStormDBObjectNotFoundError(msg % name)
Jun 26 18:27:35 ip-10-15-1-121 gunicorn[184385]: st2common.exceptions.db.StackStormDBObjectNotFoundError: The key "aws_inspector.AWSInspector:us-east-2.last_start_time_" does not exist in the StackStorm datastore.sod

# Fixed code
def get_by_scope_and_name(cls, scope, name):
    """
    Get a key value store given a scope and name.

    :param scope: Scope which the key belongs to.
    :type scope: ``str``

    :param name: Name of the key.
    :type key: ``str``

    :rtype: :class:`KeyValuePairDB` or ``None``
    """
    query_result = cls.impl.query(scope=scope, name=name)

    if not query_result:
        msg = 'The key "%s" does not exist in the StackStorm datastore.'
        raise DataStoreKeyNotFoundError(msg % name)

    return query_result.first() if query_result else None
# Buggy code
def close(self):
    self.logger.debug("Closing server connection")

    self.client.close()

    if self.socket:
        self.logger.debug("Closing proxycommand socket connection")
        # https://github.com/paramiko/paramiko/issues/789  Avoid zombie ssh processes
        self.socket.process.kill()
        self.socket.process.poll()

    if self.sftp_client:
        self.sftp_client.close()

    if self.bastion_client:
        self.bastion_client.close()

    return True


# Traceback (AttributeError)
st2actionrunner-59c47ddcc8-9jjbl r1 2020-06-25 15:30:17,009 ERROR [-] Failed shutting down SSH connection to host: rndcas402
st2actionrunner-59c47ddcc8-9jjbl r1 Traceback (most recent call last):
st2actionrunner-59c47ddcc8-9jjbl r1   File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/runners/parallel_ssh.py", line 218, in close
st2actionrunner-59c47ddcc8-9jjbl r1     self._hosts_client[host].close()
st2actionrunner-59c47ddcc8-9jjbl r1   File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/runners/paramiko_ssh.py", line 462, in close
st2actionrunner-59c47ddcc8-9jjbl r1     self.socket.process.kill()
st2actionrunner-59c47ddcc8-9jjbl r1 AttributeError: 'Channel' object has no attribute 'process'

# Fixed code
def close(self):
    if self.socket:
        self.socket.close()

    if self.client:
        self.client.close()

    if self.sftp_client:
        self.sftp_client.close()

    if self.bastion_socket:
        self.bastion_socket.close()

    if self.bastion_client:
        self.bastion_client.close()

    return True
# Buggy code
def post(self, pack_search_request):
    if hasattr(pack_search_request, "query"):
        packs = packs_service.search_pack_index(
            pack_search_request.query, case_sensitive=False
        )
        return [PackAPI(**pack) for pack in packs]
    else:
        pack = packs_service.get_pack_from_index(pack_search_request.pack)
        return PackAPI(**pack) if pack else None


# Traceback (OperationFailureException)
(virtualenv)vagrant@st2dev /m/s/s/st2 ❯❯❯ st2 --debug pack show core                                                           ⏎ master ✭ ◼
# -------- begin 139705409745296 request ----------
curl -X POST -H  'Connection: keep-alive' -H  'Accept-Encoding: gzip, deflate' -H  'Accept: */*' -H  'User-Agent: python-requests/2.13.0' -H  'content-type: application/json' -H  'Content-Length: 16' --data-binary '{"pack": "core"}' http://127.0.0.1:9101/v1/packs/index/search
# -------- begin 139705409745296 response ----------

# -------- end 139705409745296 response ------------

ERROR: Expecting value: line 1 column 1 (char 0)
CLI settings:
----------------
Config file path: /home/vagrant/.st2/config
Client settings:
----------------
ST2_BASE_URL: http://127.0.0.1
ST2_AUTH_URL: http://127.0.0.1:9100
ST2_API_URL: http://127.0.0.1:9101/v1
ST2_AUTH_TOKEN: None

Proxy settings:
---------------
HTTP_PROXY:
HTTPS_PROXY:

Traceback (most recent call last):
File "/mnt/src/storm/st2/st2client/st2client/shell.py", line 289, in run
args.func(args)
File "/mnt/src/storm/st2/st2client/st2client/commands/pack.py", line 85, in run_and_print
raise OperationFailureException(message)
OperationFailureException: Expecting value: line 1 column 1 (char 0)
(virtualenv)vagrant@st2dev /m/s/s/st2 ❯❯❯

# Fixed code
def post(self, pack_search_request):
    if hasattr(pack_search_request, "query"):
        packs = packs_service.search_pack_index(
            pack_search_request.query, case_sensitive=False
        )
        return [PackAPI(**pack) for pack in packs]
    else:
        pack = packs_service.get_pack_from_index(pack_search_request.pack)
        return PackAPI(**pack) if pack else []