Skip to content

Decorators won't catch exceptions #808

@bytestorm

Description

@bytestorm

Test code:

from functools import wraps


def catch_all(fn):
    @wraps(fn)
    def wrapper(*args, **kwargs):
        try:
            return fn(*args, **kwargs)
        except:
            log.error(f"gotcha")
            #raise
    return wrapper


@service('exception_test.test1')
def test1(**kwargs):
    try:
        raise Exception("will be caught")
    except:
        log.error("this is fine")
        #raise
# result = this is fine


@service('exception_test.test2')
@catch_all
def test2(**kwargs):
    raise Exception("will NOT be caught")
# result = exception

Expected:
"gotcha" error in logs when running exception_test.test2

Actual Result:
Exception in <file.exception_test.test2> line 32: raise Exception("will NOT be caught") ^ Exception: will NOT be caught

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions