Skip to content

six.reraise fails  #375

@northbear

Description

@northbear

HI,
We are using modernize for upgrading a code. And we get fails after replacing raise with six.reraise in a function below:

def reformat_raise_error(header='', footer=''):
    if DEBUG or (not header and not footer):
        raise
    raise sys.exc_info()[0], '%s %s %s' % (header, sys.exc_info()[1], footer), sys.exc_info()[2]

It get translated in this way:

def reformat_raise_error(header='', footer=''):
    if DEBUG or (not header and not footer):
        raise
    six.reraise(sys.exc_info()[0], '%s %s %s' % (header, sys.exc_info()[1], footer), sys.exc_info()[2])

it falls with an error: type 'str' has no attribute __trackback__.

I tried to refactor the raise call.

def reformat_raise_error(header='', footer=''):
    if DEBUG or (not header and not footer):
        raise
    t, v, tb = sys.exc_info()
    six.reraise(t, t(' '.join([header, str(v), footer])), tb)

But I got even more frustrated error when running it with python2.7:

    six.reraise(t, t(' '.join([header, str(v), footer])), tb)
TypeError: function takes exactly 5 arguments (1 given)

I'd appreciate any advice.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions